Skip to content
digiwleea Tools
Learn Open the lab →

Bitwise calculator

Apply bitwise logic, shifts and rotates to numbers. Enter decimal, binary, or hexadecimal values to see the result and how each bit is calculated.

How this tool works

Compute AND, OR, XOR, NOT, NAND, NOR, XNOR, logical and arithmetic shifts and rotates on two numbers. Enter values in decimal, hexadecimal (0x), or binary (0b) at 8, 16, or 32 bits, and see the result in binary, decimal, and hex, plus a per-bit breakdown that shows each operation is a logic gate applied column by column. For example, 12 ^ 10 = 6 (that is 1100 XOR 1010 = 0110).

How to use it

Type a number into A (and B for the two-input operations), pick an operation, and choose a bit width. Numbers can be plain decimal, hexadecimal with a 0x prefix, or binary with a 0b prefix, and a negative decimal is folded into its two's-complement pattern at the chosen width. The result updates as you type, shown in all three bases with a bit-by-bit table lining up A, B, and the output so you can see exactly which columns changed.

Worked example: 12 XOR 10

Write both numbers in binary: 12 is 1100 and 10 is 1010. XOR outputs a 1 wherever the two bits differ. Comparing column by column: the top bits are 1 and 1 (same, 0), the next are 1 and 0 (differ, 1), then 0 and 1 (differ, 1), then 0 and 0 (same, 0). The result is 0110, which is 6. That is exactly what four XOR gates in parallel would produce.

The operations

AND (&) gives 1 only where both bits are 1, the standard way to mask bits. OR (|) gives 1 where either bit is 1, used to set bits. XOR (^) gives 1 where the bits differ, used to toggle bits and to compare. NOT (~) flips every bit of a single number. NAND, NOR and XNOR are the inverted forms. A left shift (<<) multiplies by two per position and a logical right shift (>>) divides an unsigned number by two, filling the top with zeros. The arithmetic right shift (SAR) fills the top with copies of the sign bit instead, so a negative two's complement number stays negative: 11110000 (-16) SAR 2 is 11111100 (-4). Rotates (ROL, ROR) feed the bits that fall off one end back in at the other. In hardware all of these are just wiring and multiplexers: see the barrel shifter, and the bit mask calculator for setting, clearing and testing single bits.

Bitwise operators are logic gates

The point worth internalizing: a bitwise operator is nothing more than a logic gate wired up once per bit. When a CPU computes a & b on two 8-bit numbers, it runs eight AND gates in parallel, one per bit column, exactly like the table above. Build one of those gates from transistors in the lab, then line eight of them up, and you have built the AND instruction. Read the boolean algebra behind it, or see it in a real ALU.

Frequently asked

What is a bitwise XOR?

Bitwise XOR (exclusive OR, written ^) compares two numbers bit by bit and outputs a 1 in each position where the two bits differ, and 0 where they are the same. For 12 ^ 10: 1100 XOR 1010 = 0110, which is 6. It is the same operation an XOR gate performs, applied to every bit column at once.

What does bitwise AND do?

Bitwise AND (written &) outputs a 1 in a bit position only when both input bits are 1. For 12 & 10: 1100 AND 1010 = 1000, which is 8. It is commonly used to mask bits, keeping only the positions where the mask has a 1.

How do left and right shift work?

A left shift (<<) moves every bit toward the high end, filling with zeros on the right, which multiplies the value by 2 per shift. A right shift (>>) moves bits toward the low end, dividing by 2 and discarding the bits that fall off the right.

What is the difference between a logical and an arithmetic shift?

Both move bits toward the low end. A logical right shift fills the top with zeros, which divides an unsigned number by 2 per position. An arithmetic right shift copies the sign bit into the top, which divides a signed two's complement number by 2 (rounding toward minus infinity): 11110000 (-16) shifted arithmetically by 2 is 11111100 (-4). Left shifts are the same either way.

What is a bit rotation?

A rotate (ROL or ROR) shifts the bits and feeds the ones that fall off one end back in at the other, so no bit is lost: rotating 10010110 left by 1 gives 00101101. Rotates are used in hashing, cryptography and checksums.

What is the difference between bitwise operators and logic gates?

There is none, really: a bitwise operator is a logic gate applied to every bit of two numbers at once. AND, OR, XOR and NOT on numbers are the exact same gates you can build from transistors, wired one per bit position.

Bitwise operators are logic gates on numbers. Build the gates for real: open the lab and wire an AND or XOR from transistors, or read the theory on boolean algebra and logic gates.

Related tools: binary converter, truth table generator, and two's complement calculator.

Open the lab →

Embed this tool

Free to embed in your course page, blog, or notes: just keep the credit link under the widget. Paste this where you want it:

<iframe src="https://digiwleea.wleeaf.dev/embed/tool/?w=bitwise" width="100%" height="520" style="border:0;border-radius:12px;max-width:720px" title="Bitwise calculator" loading="lazy"></iframe>