Bitwise Calculator — AND, OR, XOR and shifts

AND, OR, XOR, NOT and shifts with a live bit grid so you can see exactly which bits moved.

Example: 0xCA AND 0x0F = 0x0A (10, 0b00001010).

Check it against real silicon

Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.

Chiprun docs

Formula

result = a ⊕ b, masked to the register width

Worked example

0xCA AND 0x0F = 0x0A (10, 0b00001010).

  1. AND (a & b)

    1100 1010 0000 1111

    0000 1010

Frequently asked questions

How do I clear a specific bit?

AND with the complement of that bit: `x &= ~(1 << n)`. To set one, OR with it: `x |= (1 << n)`. To flip it, XOR: `x ^= (1 << n)`. To test it, AND and check for non-zero.

Is shifting left the same as multiplying by two?

Only while nothing overflows. Left-shifting a fixed-width value discards bits that fall off the top, so once the result exceeds the register width the equivalence breaks. This tool flags it when that happens.

Why do I get a different answer in JavaScript?

Because JavaScript's bitwise operators convert to signed 32-bit integers first. Any value above 2³¹−1, or any 64-bit operation, gives a wrong result. This calculator uses BigInt throughout to avoid exactly that.

What is the difference between logical and arithmetic right shift?

Arithmetic shift preserves the sign by copying the top bit in; logical shift brings in zeros. In C, shifting an unsigned type is logical and shifting a signed negative value is implementation-defined — which is a good reason to do bit manipulation on unsigned types only.

Related tools