Skip to main content

Thread: Bit level or byte level access in C?


im little confused how bit level access blocks of memory in c.

ive allocated memory in device driver using kmalloc 12 bytes long, dont want access in bytes want individual bits.

understand copy_to_user function works @ byte level? how can access individual bits?

thanks
aw

the smallest addressable unit byte (as suppose know). state of bit (or bits) within byte use "mask" appropriate bit(s) or employing bit-shifting examine particular bit.

here's examples:
code:
const int mask = 0x04;   /* same 00000100 in binary */    unsigned char byte = buffer[5];    if (byte & mask)  {     /* bit 2 set (note, bits range 0-7) */  }  else  {     /* bit not set  }
code:
unsigned char byte = buffer[5];    if ((byte >> 2) & 0x1)  {     /* bit 2 set (note, bits range 0-7) */  }  else  {     /* bit not set */  }
i hope helps.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Bit level or byte level access in C?


Ubuntu

Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO