Bit Manipulation, Bitwise Masks & Binary Shifts
Bitwise operations and masks let a program change or test individual bits. You will use AND, OR and XOR with masks, and shifts to multiply or divide by powers of two.
Key terms
- AND mask
- AND with 0s clears bits. 10110101 AND 11110000 gives 10110000.
- OR mask
- OR with 1s sets bits to 1. 10110101 OR 00001111 gives 10111111.
- XOR mask
- XOR with 1s flips bits. 10110101 XOR 11111111 gives 01001010.
- Binary shift
- Moves bits left or right. A left shift by 1 multiplies by 2.
Part of Processor Fundamentals.