Tool · 2026-06-08
Bitwise, by the bit.
Two 32-bit registers, each a row of clickable cells. Toggle any bit or type a value into the inputs. The boolean operations below recompute on every change, so you can watch a carry-free AND eat the bits B doesn't have, or an XOR mark exactly where the two registers disagree.
Register A
Register B
Operations
- A & -A
- 0x00000000 · (zero)
- A | (A-1)
- 0x00000000
- A << 1
- 0x00000000
- A >> 1 (arithmetic)
- 0x00000000
- A >>> 1 (logical)
- 0x00000000
What the operations do
AND keeps a bit only when both registers have it set; it's how you mask out everything except the bits you care about. OR keeps a bit when either register has it; it's how you union flags. XOR keeps a bit only where the two disagree, which makes it the no-spill difference detector and the cheap toggle. NOT flips every bit of A, which in two's complement is exactly -A - 1.
The bit tricks
A & -A isolates the lowest set bit. Negation flips every bit then adds one, so the lowest set bit lines up in both A and -A and every higher bit disagrees. AND wipes the disagreements and leaves the single bit. A | (A-1) smears that lowest bit downward, setting every bit below the lowest one in A; useful for rounding down to a power-of-two boundary. The shifts split into two flavours: arithmetic right shift drags the sign bit in to preserve sign, logical right shift drags in zero.
A note on width
JavaScript numbers are 64-bit floats, but the bitwise operators cast to a 32-bit integer first. That is the only reason this page can show a register as 32 cells and stay honest. The unsigned input accepts values from 0 to 4294967295. The signed input goes from -2147483648 to 2147483647, the two's complement range. Type anything outside those bounds and the field marks itself invalid rather than silently wrapping.