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 }i hope helps.code:unsigned char byte = buffer[5]; if ((byte >> 2) & 0x1) { /* bit 2 set (note, bits range 0-7) */ } else { /* bit not set */ }
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Bit level or byte level access in C?
Ubuntu
Comments
Post a Comment