Bit manipulation
Bit manipulation is often used for tasks like setting, clearing, or toggling specific bits, as well as optimizing certain algorithms and data structures.
Bitwise operations involve manipulating individual bits in binary representations of numbers.
The most common bitwise operators include AND (&
), OR (|
), XOR (^
), left shift (<<
), and right shift (>>
).
- AND and OR operations compare corresponding bits
- XOR toggles bits
- left shift multiplies by powers of 2
- right shift divides by powers of 2