i should add to this
A mini catalogue of every bit manipulation trick I'll ever need
(recap: one byte = 8 bits = 2 nibbles)
32 bits = one word of memory for 32-bit systems
0000 0000 0000 0000 0000 0000 0000 0000
^ MSB ^ LSB
- Bitwise operations
>>
is arithmethic left shift. The result ofa >> b
is everything ina
shifted left byb
places -- equivalent to multiplying by 2^n (assuming no overflow). So1 >> 2 = 0000 0001 >> 2 = 0000 0100 (4)
- Operators in C, C++
- How to set, unset, toggle, etc a bit
- Format specifiers when printing strings
const int NUM = 5;
int arr[NUM];
doesn't compile for reasons.