Cpp - bit manipulation Flashcards
What is the smallest addressable unit of memory
A byte
How many bits in a byte
8
How to define a set of bit flags?
include
std::bitset<8> mybitset {};
What does test() do
Query whether a bit is a 0 or 1
what does set() do
Turn a bit on
reset()
turn a bit off
flip()
flip a bit value to its opposite
What are the following bitwise operator
<< >> ~ & | ^
left shift right shift bitwise NOT bitwise AND bitwise OR bitwise XOR
What does std::cout do to «_space;and»_space;
it overloads it so it performances a console output rather than a shift
Whats a bit mask
A predefined set of bits that is used to select which bits will be modified by subsequent operations
How to define bit masks
include
constexpr std::uint8_t mask{ 0b0000’0001 }; represents bit 0
test to see if bit is on or off
take the flags and bitwise AND it with the mask
setting a bit
take the flag and bitwise OR assignment it to the mask
Reset a bit
Take the flags then bitwise AND assignment it to the NOT of the mask