Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

rwil::BitOp Namespace Reference


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...


Function Documentation

int rwil::BitOp::GetBit char *    data,
int    bit
 

Get the value of a single bit in data.

Returns a 0 or one depending on the value of a specific bit

Parameters:
data  The memory buffer to examine
bit  The number of the specific bit to look at
Returns:
The value of the bit, 0 or 1

Definition at line 30 of file BitOp.cpp.

00031     {
00032       return data[bit/8] & (1 << (7-bit%8))?1:0;
00033     }

int rwil::BitOp::GetBits char *    data,
int    startbit,
int    numbits
 

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

Parameters:
data  The memory buffer to examine
startbit  The number of the first bit to examine
numbits  The number of bits of data to extract max 32
Returns:
The bit 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     }

void rwil::BitOp::PrintBits char *    data,
int    bits
 

Print a series of bits.

Print to stdout a series of one's and zeroes starting with the lsb.

Parameters:
data  The memory buffer to display
bits  The number of bits to display from data.

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     }

void rwil::BitOp::SetBit char *    data,
int    bit,
int    val
 

Set the value of a specific bit.

Sets the value of a specific bit to val. val must be 0 or 1

Parameters:
data  The memory buffer to modify
bit  The number of the specific bit to modify @val The new value of the bit, 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     }

void rwil::BitOp::SetBits char *    data,
int    startbit,
int    numbits,
int    val
 

Sets the value of up to 32 bits at a time.

Sets the value of up to 32 consecutive bits at a time.

Parameters:
data  The memory buffer to modify.
startbit  The identifier of the first bit to modify
numbits  The number of bits to modify, max 32
val  An integer representing a bit vector that is the new bit values.

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     }


Generated on Tue Apr 9 13:53:09 2002 for RWIL - Real World Interface Library by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001