Illustration of bitwise AND, OR, and XOR operations on binary numbers with logic gate symbols.

Bitwise Operations

Fixed-width bitwise operations

Operands are unsigned integers. Results are masked to the chosen width. Shifts use the shift count (modulo bit width). NOT uses operand A only.

Operation

Operand A

Operand B

Result

Arithmetic right shift treats the value as two’s complement signed before shifting; logical right shift fills with zeros.

How these bitwise operations work

Bit-level logic on fixed widths

Bitwise operators treat an integer as a bundle of binary digits. This page performs AND, OR, XOR, NOT, and shifts on unsigned values masked to 8, 16, or 32 bits. Results stay within that width so they match common microcontroller and low-level programming behaviour more closely than infinite-precision maths.

Operators

  • AND — bit is 1 only if both inputs have 1 (masking flags).
  • OR — bit is 1 if either input has 1 (setting flags).
  • XOR — bit is 1 if inputs differ (toggles / parity).
  • NOT — flips every bit of operand A, still masked to width.
  • Shifts — move bits left/right; count is taken modulo the bit width.

Worked example

In 8-bit width, 0b11001100 AND 0b10101010 yields 0b10001000. A left shift by 1 multiplies by two (if no bits fall off the end); shifting beyond the width wraps the count so oversized counts stay meaningful on fixed registers.

Unsigned masking

Because values are unsigned and masked, NOT on 8 bits of 0x0F is 0xF0, not an infinite string of leading ones. That matches uint8_t-style thinking in C more than signed unlimited integers in some scripting languages.

Common mistakes

  • Confusing bitwise AND/OR with boolean && / || on whole values.
  • Forgetting that arithmetic right shift (sign-extending) differs from logical shift — this page’s unsigned model is logical.
  • Using XOR when you meant OR for combining flag bits.

FAQs

Where do truth tables fit?
Single-bit boolean behaviour is charted on Boolean Truth Tables.
How do I view the bits another way?
Convert with Number Bases or Signed & Unsigned.

Related: Truth Tables, Signed & Unsigned, Number Bases.

Last updated: July 2026