source: http://www.learncpp.com/cpp-tutorial/3-8a-bit-flags-and-bit-masks/
If you are using simple booleans, the above example displays how you can adress them to seperate bit values inside of bytes.
C++14
Define 8 separate bit flags (these can represent whatever you want)
const unsigned char option1 = 0b0000'0001;
const unsigned char option2 = 0b0000'0010;
const unsigned char option3 = 0b0000'0100;
const unsigned char option4 = 0b0000'1000;
const unsigned char option5 = 0b0001'0000;
const unsigned char option6 = 0b0010'0000;
const unsigned char option7 = 0b0100'0000;
const unsigned char option8 = 0b1000'0000;
C++11 or earlier
Define 8 separate bit flags (these can represent whatever you want)
const unsigned char option1 = 0x1; // hex for 0000 0001
const unsigned char option2 = 0x2; // hex for 0000 0010
const unsigned char option3 = 0x4; // hex for 0000 0100
const unsigned char option4 = 0x8; // hex for 0000 1000
const unsigned char option5 = 0x10; // hex for 0001 0000
const unsigned char option6 = 0x20; // hex for 0010 0000
const unsigned char option7 = 0x40; // hex for 0100 0000
const unsigned char option8 = 0x80; // hex for 1000 0000
We use a byte-size value to hold our options
Each bit in myflags corresponds to one of the options defined above
unsigned char myflags = 0; -- all options turned off to start
To query a bit state, we use bitwise AND ('&' operator):
if (myflags & option4) ... -- if option4 is set, do something
if !(myflags & option5) ... -- if option5 is not set, do something
To set a bit (turn on), we use bitwise OR('|' operator):
myflags |= option4; -- turn option 4 on.
myflags |= (option4 | option5); -- turn options 4 and 5 on.
To clear a bit (turn off), we use bitwise AND with an inverse(~) bit pattern:
myflags &= ~option4; -- turn option 4 off
myflags &= ~(option4 | option5); -- turn options 4 and 5 off
To toggle a bit state, we use bitwise XOR:
myflags ^= option4; -- flip option4 from on to off, or vice versa
myflags ^= (option4 | option5); -- flip options 4 and 5
You can use: static_cast(value) to turn said value into a bool.