Bitwise Operation Simulator (AND, OR, XOR, NOT, Shift)
Compute AND, OR, XOR, NOT, left shift, and right shift on two numbers and visualize exactly which bits changed on a binary grid. Supports 8/16/32-bit widths.
Usage Tips
- You can enter values in decimal, or use a `0x1A` hexadecimal or `0b1010` binary prefix. Paste values straight from your code, exactly as you'd write them in a program.
- AND, OR, and XOR use two values, while NOT uses only one. The number of input fields changes automatically depending on the operation you pick.
- Right shift (`>>>`) only supports the logical variant here. See the FAQ for how it differs from an arithmetic shift that preserves the sign bit.
- Switching the bit width from 8 to 16 to 32 lets you see the same number gain more leading zero bits, which is a great way to build intuition for what "bit width" actually means.
- Bits highlighted in yellow are the ones that changed between A and the result, so with AND/OR you can visually trace which input "won" at each bit position.
Frequently Asked Questions
Side Note — The Curious Properties of XOR
Bitwise operations map directly onto a computer's logic circuits, making them among the fastest operations a CPU can execute — often a single clock cycle. Because they need far simpler circuitry than arithmetic like multiplication or division, performance-critical code (image processing, cryptography, network protocol implementations) has long used bitwise tricks as substitutes for costlier arithmetic.
XOR (exclusive OR) has a couple of neat properties: XOR-ing a value with itself always yields 0 (`a ^ a = 0`), and XOR-ing with 0 returns the original value unchanged (`a ^ 0 = a`). Combining these two facts gives rise to the classic "XOR swap" trick, which exchanges two variables without a temporary one (`a ^= b; b ^= a; a ^= b;`). It's rarely recommended in production code today for readability reasons, but it remains a favorite teaching example for bitwise intuition.
Bitmasks show up constantly in real-world systems. Unix file permissions (read=4, write=2, execute=1) are literally bitwise OR and AND at work, and pulling the red, green, and blue components out of a color code like `#FF0000` is done with a right shift combined with an AND mask. Packing many on/off flags into a single integer — a technique often called "bit flags" — was widely used in older games and systems that needed to track a lot of state with very little memory.