How do I create a 3 bit variable as datatype in C? -


this question has answer here:

i can typedef char char1 8 bits. how can make 3 bit variable datatype?

you might want similar following:

struct {   .   .   .   unsigned int fieldof3bits : 3;   .   .   . } newdatatypename; 

in case, fieldof3bits takes 3 bits in structure (based upon how define else, size of structure might vary though).

this usage called bit field.

from wikipedia:

a bit field term used in computer programming store multiple, logical, neighboring bits, each of sets of bits, , single bits can addressed. bit field commonly used represent integral types of known, fixed bit-width.


Comments