Bitwise calculator

Combine two numbers with AND, OR, XOR, invert one with NOT, or shift and rotate its bits. Type hex (0x), binary (0b) or decimal, pick 8, 16, 32 or 64 bits, and see every bit of A, B and the result lined up column by column.

Try:
Operation
Base for unprefixed input
Bit width

The result appears here as you type.

HEX
BIN
DEC (unsigned)
DEC (signed)

How each operation works

AND, OR and XOR compare the two operands one column at a time, so each result bit depends only on the two bits directly above it:

ABA AND BA OR BA XOR B
00000
01011
10011
11110

NOT flips every bit inside the chosen width, which is why NOT 0x0F is 0xF0 at 8 bits but 0xFFFFFFF0 at 32. << slides all bits left and fills the gap with zeros; >> slides them right, again filling with zeros (a logical shift — this tool treats values as unsigned patterns, so the sign-copying arithmetic shift is not applied). ROL and ROR rotate instead of shifting: bits that fall off one end reappear at the other.

Masks: setting, clearing and testing bits

Most real-world bitwise work is flag handling on a byte or a register. Three idioms cover it, shown here at 8 bits:

Set bit 3 — OR with a mask that has only that bit on:

0x41 OR 0x08 → 0100 0001 | 0000 1000 = 0100 1001 = 0x49

Clear bit 0 — AND with the inverted mask (NOT 0x01 = 0xFE):

0x49 AND 0xFE → 0100 1001 & 1111 1110 = 0100 1000 = 0x48

Test bit 6 — AND with the mask and check whether the result is non-zero:

0x48 AND 0x40 → 0100 1000 & 0100 0000 = 0100 0000 = 0x40 ≠ 0 → the bit is set

XOR with the same mask toggles the bit instead, and a value XORed with itself is always zero — handy for clearing a register in one instruction.

Shifts as multiplication and division

Because binary is positional, moving every bit one place left doubles the value and moving it right halves it: x << n equals x × 2ⁿ and x >> n equals x ÷ 2ⁿ, rounded down.

0x05 << 2 → 0000 0101 → 0001 0100 = 0x14 (5 × 4 = 20)

0x14 >> 2 → 0001 0100 → 0000 0101 = 0x05 (20 ÷ 4 = 5)

At a fixed width the multiplication silently overflows: any bit pushed past the top is lost. At 8 bits 0xC0 << 1 gives 0x80, not 0x180, because 192 × 2 = 384 does not fit in a byte. Switch the bit width above to watch which bits survive.

Related tools and guides