Skip to main content
Be Bitwise

Bitwise AND, OR, NOT

Apply bitwise AND, OR, and NOT to register values and watch how individual bits change. The foundation of all digital logic.

Logic gates operate on individual bits: AND outputs 1 only when both inputs are 1, OR outputs 1 when either input is 1, and NOT flips every bit. When a CPU applies these operations to entire registers, it performs the gate logic on each bit position independently. Bitwise operations are used for masking, setting, clearing, and toggling individual bits — essential in systems programming, networking, and hardware control.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Load the operands

    Do this: Step through both MOV instructions for R0 and R1

    Watch for: R0 = 5 (binary 0101), R1 = 3 (binary 0011)

    We load two small values whose binary representations make the bit-level logic easy to follow. 5 = 0101 and 3 = 0011 — each has a different pattern of set bits.

  2. 2

    Bitwise AND

    Do this: Step through MOV R2, R0 then AND R2, R1

    Watch for: R2 = 1 (binary 0001)

    AND compares each bit position: 0&0=0, 1&0=0, 0&1=0, 1&1=1. Only bit 0 is set in both values, so only bit 0 survives. AND is used to 'mask' — to extract specific bits from a value.

  3. 3

    Bitwise OR

    Do this: Step through MOV R3, R0 then OR R3, R1

    Watch for: R3 = 7 (binary 0111)

    OR sets a bit if it is set in either input: 0|0=0, 1|0=1, 0|1=1, 1|1=1. Bits 0, 1, and 2 are set in at least one operand, giving 0111 = 7. OR is used to 'set' specific bits.

  4. 4

    Bitwise NOT

    Do this: Step through MOV R4, R0 then NOT R4

    Watch for: R4 = 250 (binary 11111010)

    NOT flips every bit in the register: 00000101 becomes 11111010 = 250. This is a unary operation — it only needs one operand. NOT is used to compute one's complement and to invert bitmasks.

Objectives

  • •See R2 become 1 after AND - only bit 0 is set in both values
  • •See R3 become 7 after OR - bits set in either value are kept
  • •See R4 become 250 after NOT - every bit in R0 is flipped
  • •Compare the binary representations: AND keeps common bits, OR merges them

Hints

  • Think of AND as asking 'which bits are on in BOTH values?' and OR as 'which bits are on in EITHER value?'