Add
= 10 (unsigned 8-bit)
= 6 (unsigned 8-bit)
0001 0000
16
0o20
0x10
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| A | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
| B | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| + | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
0000 1010 (10) + 0000 0110 (6) ─────────── = 0001 0000 (16)
Both bits must be 1 for result 1. Used to mask/clear bits.
Either bit being 1 gives 1. Used to set specific bits.
Different bits give 1, same give 0. Used to toggle bits.
Signed integers use MSB as sign. Negate by flipping bits + 1.
Shifts bits left, fills with 0s. Equivalent to multiplying by 2^n.
Shifts bits right. Logical fills with 0s; arithmetic preserves sign.