Quiz Entry - updated: 2026.07.14
What is the difference between logical operators (&&, ||, !) and bitwise operators (&, |, ~)?
Logical operators (&& || !) treat the whole value as one true/false; bitwise operators (& | ~) act on each bit separately.
| Operation | Logical | Bitwise |
|---|---|---|
| AND | && |
& |
| OR | || |
| |
| NOT | ! |
~ |
Example with x = 0x41 = 01000001, y = 0x00:
!x = 0x00 (false, because x is non-zero)
~x = 0xBE (10111110, each bit inverted)
x && y = 0x00 (false AND false)
x & y = 0x00 (bitwise AND)
Warning: && and || short-circuit evaluate; & and | always evaluate both sides.