Bitwise Operations Calculator – AND, OR, XOR, NOT, Shifts

Perform all bitwise operations (AND, OR, XOR, NOT, NAND, NOR, XNOR, shifts) on two numbers with step-by-step binary breakdown, bit grid visualization, and operations comparison table.

A AND B
0
Bits set in both A and B — masking/clearing bits
A OR B
255
Bits set in A or B (or both) — setting bits
A XOR B
255
Bits that differ between A and B — toggling bits
NOT A
85
Every bit of A flipped — 8-bit complement
NAND
255
NOT(A AND B) — universal gate
NOR
0
NOT(A OR B) — universal gate
A << 1
84
Left shift: multiply by 2^1
A >>> 1
85
Logical right shift: divide by 2^1

Bit Grid Visualization

b7
1
0
0
1
1
b6
0
1
0
1
1
b5
1
0
0
1
1
b4
0
1
0
1
1
b3
1
0
0
1
1
b2
0
1
0
1
1
b1
1
0
0
1
1
b0
0
1
0
1
1
🔵 A🟡 B🟢 AND🟣 OR⬤ XOR

All Operations Comparison

OperationSymbolDecimalBinaryHex
Input AA170101010100xAA
Input BB85010101010x55
AND&0000000000x0
OR|255111111110xFF
XOR^255111111110xFF
NOT A~A85010101010x55
NOT B~B170101010100xAA
NAND~(A&B)255111111110xFF
NOR~(A|B)0000000000x0
XNOR~(A^B)0000000000x0
A << 1A<<184010101000x54
A >>> 1A>>>185010101010x55

Bitwise Operations Quick Reference

OperationDescriptionCommon Use
AND (&)Both bits must be 1Masking, clearing bits, checking flags
OR (|)Either bit is 1Setting bits, combining flags
XOR (^)Bits must differToggling bits, encryption, swap
NOT (~)Flip every bitComplement, inverting masks
NANDNOT(AND)Universal gate, flash memory
NORNOT(OR)Universal gate, circuit design
XNORNOT(XOR)Equality check per bit
Left Shift (<<)Shift bits left, fill 0sMultiply by 2ⁿ, create masks
Right Shift (>>>)Shift bits right, fill 0sUnsigned divide by 2ⁿ
Planning notes, formulas, and examples

About the Bitwise Operations Calculator – AND, OR, XOR, NOT, Shifts

Bitwise operations are the building blocks of low-level programming, forming the foundation for everything from hardware design to efficient algorithms. Every processor executes these operations in a single clock cycle, making them the fastest possible computations a computer can perform. Understanding bitwise operations is essential for systems programming, embedded development, cryptography, graphics, and networking.

This combined bitwise calculator applies all major operations — AND, OR, XOR, NOT, NAND, NOR, XNOR, and bit shifts — to a pair of input numbers simultaneously. Instead of switching between separate views, you see every operation's result side by side, making it easy to compare how different operations transform the same inputs.

The bit grid visualization displays each bit position with colour-coded results for AND, OR, and XOR, revealing the visual pattern of how each operation selects, combines, or differentiates bits. The comprehensive operations table shows every result in decimal, binary, and hexadecimal, while the quick reference table summarises each operation's purpose and common applications.

Whether you're debugging bitmask logic, studying for a computer science exam, or designing hardware, the page keeps the major operations in one comparison view. Configure bit widths from 4 to 32 bits, adjust shift amounts, switch display bases, and use presets to explore classic bitwise patterns quickly.

When This Page Helps

Evaluating AND, OR, XOR, NAND, NOR, XNOR, NOT, and shifts for a pair of numbers by hand means writing out long binary columns for each operation — eight separate calculations that are tedious. This calculator performs all of them at once and displays every result in decimal, binary, and hex alongside a colour-coded bit grid. Embedded firmware developers can verify bitmask logic, digital-logic students can compare truth-table outputs visually, and anyone debugging bitwise code can see where operations start to diverge.

How to Use the Inputs

  1. Enter two integer values (Input A and Input B).
  2. Set a shift amount for the shift operations (0–31).
  3. Choose a bit width (4, 8, 16, or 32 bits).
  4. Optionally change the display base (decimal, binary, or hex).
  5. View all operations results in the output cards.
  6. Examine the bit grid to see per-bit results visually.
  7. Browse the all-operations comparison table for complete details.
  8. Use preset buttons to load common test cases.
Formula used
AND: both bits 1 → 1. OR: either bit 1 → 1. XOR: bits differ → 1. NOT: flip bit. NAND: NOT(AND). NOR: NOT(OR). XNOR: NOT(XOR). Left shift: A × 2ⁿ. Right shift: A ÷ 2ⁿ.

Example Calculation

Result: AND=0, OR=255, XOR=255, NOT A=85, NAND=255, NOR=0

170 (10101010) and 85 (01010101) are complementary bit patterns. AND gives 0 (no shared bits), OR and XOR both give 255 (all bits), and NOT A equals B.

Tips & Best Practices

  • Complementary inputs (like 170 and 85 in 8-bit) make AND=0 and OR=MAX — great for testing.
  • Use AND with a mask to extract specific bits: value & 0x0F gets the lower nibble.
  • Use OR to set flags: flags | FLAG_ENABLED turns on a specific bit.
  • XOR with the same value twice restores the original — used in encryption and swap.
  • NAND and NOR are universal gates — either alone can build any logic circuit.
  • The bit grid visualization helps spot bit patterns that are hard to see in numbers.

The Eight Core Bitwise Operations

At the heart of every CPU sit eight operations that share a single trait: they work on each bit independently. **AND** outputs 1 only when both bits are 1 — used for masking and clearing bits. **OR** outputs 1 when at least one bit is 1 — used for setting bits. **XOR** outputs 1 when the bits differ — used for toggling and parity checks. **NOT** flips every bit — it computes the one's complement. From these four, the inverted gates follow: **NAND** = NOT(AND), **NOR** = NOT(OR), **XNOR** = NOT(XOR). Finally, **shifts** move all bits left or right, multiplying or dividing by powers of two.

Real-World Applications of Bit Manipulation

Bit manipulation is ubiquitous in systems programming. **Flags and permissions** pack multiple booleans into a single integer; the Unix file-permission bits (rwxr-xr-x) are tested with AND masks. **Colour channels** in 32-bit ARGB values are extracted with masks and shifts: `(pixel >> 16) & 0xFF` gets the red channel. **Network protocols** use AND to compute subnet prefixes and XOR for checksums. **Encryption algorithms** like AES mix operations of XOR, shifts, and substitution. **Graphics shaders** lean on XOR and shifts for pseudo-random noise and hash functions. Even high-level algorithms benefit: XOR-swap saves a temporary variable, and Brian Kernighan's trick (`n & (n-1)` clears the lowest set bit) counts population (set bits) efficiently.

Universal Gates and Digital Logic Design

NAND and NOR are called *universal* gates because any Boolean function can be built from copies of just one of them. For example, NOT A = A NAND A, and A AND B = (A NAND B) NAND (A NAND B). Integrated circuits often use NAND-only or NOR-only implementations because manufacturing a single gate type is cheaper. Understanding these equivalences helps digital-logic students simplify circuits using Karnaugh maps or the Quine-McCluskey algorithm, and it gives programmers insight into how high-level expressions compile down to transistor-level logic.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • Bitwise operations work on individual bits of integers. They include AND, OR, XOR, NOT, and shifts. Each operation has a truth-table-defined behaviour per bit position, applied simultaneously across all bits.