Bitwise Operators
Operate on individual bits: AND, OR, XOR, NOT and shifts — the language of hardware registers.
Easy
| Operator | Meaning | Example (a = 0b1100, b = 0b1010) |
|---|---|---|
& | AND | a & b = 0b1000 |
| | OR | a | b = 0b1110 |
^ | XOR | a ^ b = 0b0110 |
~ | NOT | inverts every bit |
<< | shift left | 1 << 3 = 0b1000 |
>> | shift right | 0b1000 >> 2 = 0b0010 |
Shifting left by multiplies by ; shifting right divides (for unsigned values).
Sub-topics (1)
Bit Masking
Set, clear, toggle and test individual bits of a register using masks.
Easy♥ 0🔖 0💬 0
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.