The smallest number of bits you can get and save is 8 = 1 byte. You can access bits in bytes using the ^ and | bitwise operators.
You can set the nth bit to 1 using:
my_byte = my_byte | (1 << n);
where n is 0-7.
You can set the nth bit to 0 using:
my_byte = my_byte & ((~1) << n);
You can switch the nth bit using:
my_byte = my_byte ^ (1 << n);
More details here .
klew
source share