Pages

2010-10-12

C Programming: Bit Masking

Bit Masking Table:
1     - > Bit 1
2     - > Bit 2
4     - > Bit 3
8     - > Bit 4
16   - > Bit 5
32   - > Bit 6
64   - > Bit 7
128 - > Bit 8
Example:
if(buffer[0] & 1 == 0) 
{
    // Frist bit is set to 0
}
else
{
   // First bit is set to 1

if(buffer[0] & 64 == 0) 
{
    // Bit number 7 is set to 0
}
else
{
    // Bit number 7 is set to 1
}

No comments:

Post a Comment