Functions | |
void | SetBit (char *data, int bit, int val) |
Set the value of a specific bit. More... | |
void | SetBits (char *data, int startbit, int numbits, int val) |
Sets the value of up to 32 bits at a time. More... | |
int | GetBit (char *data, int bit) |
Get the value of a single bit in data. More... | |
int | GetBits (char *data, int startbit, int numbits) |
Gets the value of up to 32 bits. More... | |
void | PrintBits (char *data, int bits) |
Print a series of bits. More... |
|
Get the value of a single bit in data. Returns a 0 or one depending on the value of a specific bit
Definition at line 30 of file BitOp.cpp.
00031 { 00032 return data[bit/8] & (1 << (7-bit%8))?1:0; 00033 } |
|
Gets the value of up to 32 bits. Returns an integer with the first numbits of it set to the desired bits from the data
Definition at line 35 of file BitOp.cpp.
00036 { 00037 int count; 00038 int retval = 0; 00039 for(count=0;count<numbits;count++) 00040 { 00041 retval += GetBit(data, startbit + numbits - count - 1) << count; 00042 } 00043 return retval; 00044 } |
|
Print a series of bits. Print to stdout a series of one's and zeroes starting with the lsb.
Definition at line 46 of file BitOp.cpp.
00047 { 00048 int count; 00049 for(count=0;count<bits;count++) 00050 { 00051 if(!(count%8)) printf("-"); 00052 printf("%d", data[count/8] & (1 << (7-count%8))?1:0); 00053 } 00054 printf("\n"); 00055 } |
|
Set the value of a specific bit. Sets the value of a specific bit to val. val must be 0 or 1
Definition at line 12 of file BitOp.cpp.
00013 { 00014 int byte = bit/8; 00015 int loc = 7-bit%8; 00016 data[byte] = data[byte] & (~(1 << loc)) | (val << loc); 00017 } |
|
Sets the value of up to 32 bits at a time. Sets the value of up to 32 consecutive bits at a time.
Definition at line 19 of file BitOp.cpp.
00020 { 00021 int count; 00022 for(count=0;count<numbits;count++) 00023 { 00024 // printf("%d=", val & (1 << count)); 00025 SetBit(data, startbit+numbits- 1 - count, val & (1 << count)?1:0); 00026 } 00027 // printf("\n"); 00028 } |