| Bitwise operators | |||||||||||
| Logical operators | |||||||||||
| &&, || | and, or | ||||||||||
| operate on entire value | |||||||||||
| int x = 0, y = 1; | |||||||||||
| (x && y) | value 0 | ||||||||||
| (x || y) | value 1 | ||||||||||
| May want to work with individual bits | |||||||||||
| int x = 2, y = 7; | |||||||||||
| (x && y) | value 1 | ||||||||||
| What about bits? | value | ||||||||||
| x | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0010 | 2 | ||
| y | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0111 | 7 | ||
| Bitwise and | |||||||||||
| x & y | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0000 | 0010 | 2 | ||