LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

How do bitwise operators work at the bit level in C?

Bitwise operators (& | ~ ^ << >>) work bit-by-bit on any integer type: AND keeps bits set in both, OR sets bits set in either, XOR sets bits that differ, and NOT flips every bit.

AND, OR, XOR, NOT on bytes

* AND keeps the common 1-bits, OR sets either operand's 1-bits, XOR sets the differing bits, and NOT flips them all — shown on 0x69 and 0x55. *

Operations: & | ~ ^ << >>

NOT (~) - Flip all bits:

~0x41  →  0xBE
~01000001₂  →  10111110₂

~0x00  →  0xFF
~00000000₂  →  11111111₂

AND (&) - Both bits must be 1:

0x69 & 0x55  →  0x41
01101001₂ & 01010101₂  →  01000001₂

OR (|) - Either bit can be 1:

0x69 | 0x55  →  0x7D
01101001₂ | 01010101₂  →  01111101₂

XOR (^) - Exactly one bit must be 1:

0x69 ^ 0x55  →  0x3C
01101001₂ ^ 01010101₂  →  00111100₂

Common uses:

  • Masking: value & 0xFF extracts lowest byte
  • Setting bits: flags | FLAG_BIT
  • Clearing bits: flags & ~FLAG_BIT
  • Toggling bits: flags ^ FLAG_BIT
  • Checking bits: if (flags & FLAG_BIT)

Go deeper:

From Quiz: REVE1 / C Programming | Updated: Jul 10, 2026