Skip to content
K Knidox Search…
Computer Science · Bit operations

Bitwise Calculator

AND, OR, XOR, NOT, and bit shifts on two integers.

Operation
12 & 10 =
8

Operands and result shown in binary below.

ValueDecimalBinary (32-bit signed)
A121100
B101010
Result81000

A bitwise operation lines up two integers in binary and combines them one bit at a time. For example, 12 & 10 = 8, because 12 is 1100 and 10 is 1010, and AND keeps a 1 only where both have a 1 — giving 1000, which is 8.

What bitwise operators do

Every integer is stored as a row of bits. A bitwise operator compares the two numbers bit by bit, in the same column, and produces a new bit for each column. AND, OR, and XOR each take two operands; NOT (~) takes one operand and flips every bit. The shift operators slide the bits of the first operand left or right by the number of places given in the second operand. JavaScript performs these on 32-bit signed integers, which is the model this calculator follows.

The six operators

How each one combines or moves bits.

OperatorSymbolMeaning
AND&Result bit is 1 only when both input bits are 1.
OR|Result bit is 1 when either input bit is 1.
XOR^Result bit is 1 when the two input bits differ.
NOT~Flips every bit of one operand; ~n = −n − 1.
Left shift<<Moves bits left by n places, filling 0 on the right (× 2ⁿ).
Right shift>>Moves bits right by n places, keeping the sign (÷ 2ⁿ, floored).

Worked example: 12 & 10

AND keeps a bit only where both numbers have a 1 in that column. Writing both in binary and comparing column by column gives the answer directly.

  1. 1
    Write both operands in binary. 12 = 1100 and 10 = 1010. Pad them to the same width so the columns line up.
  2. 2
    Line the bits up in columns. 1100 over 1010 — each position now has a top bit and a bottom bit.
  3. 3
    Apply AND to each column. Keep a 1 only when both bits are 1: columns give 1, 0, 0, 0 → 1000.
  4. 4
    Convert the result to decimal. 1000 in binary is 8, so 12 & 10 = 8.

Where bit operations are used

Bitwise work shows up wherever you pack many yes/no facts into one integer. AND with a mask isolates specific bits (for example x & 0xFF keeps the low byte); OR sets flags on; XOR toggles them. Shifts are a fast way to multiply or divide by powers of two: x << 1 doubles a value and x >> 1 halves it (rounding toward negative infinity). Remember that JavaScript treats operands as 32-bit signed integers, so the top bit is the sign and NOT returns ~n = −n − 1 rather than a large positive number.

What do AND, OR, and XOR actually compute?
They combine two numbers bit by bit. AND outputs a 1 only when both bits are 1, OR outputs a 1 when either bit is 1, and XOR outputs a 1 only when the two bits differ.
What does the NOT operator (~) return?
NOT flips every bit of a single operand. Because the value is a 32-bit signed integer, the result follows ~n = −n − 1 — for example ~5 is −6 and ~0 is −1.
What do the shift operators do?
Left shift (<<) moves bits toward the high end, which multiplies by 2ⁿ; right shift (>>) moves them toward the low end, which divides by 2ⁿ and floors the result. Shifting 1 by 3 (1 << 3) gives 8.
Why are the results 32-bit?
JavaScript converts operands to 32-bit signed integers before any bitwise operation, so values wrap at that width and the most significant bit acts as the sign. This calculator mirrors that exact behavior.
How do masks and flags use bitwise operators?
A mask is an integer whose 1-bits mark the positions you care about. AND with a mask reads those bits, OR with a mask turns them on, and XOR with a mask toggles them — the basis of packing many boolean flags into one number.
Why is 12 & 10 equal to 8?
In binary 12 is 1100 and 10 is 1010. AND keeps a 1 only where both have a 1, which happens only in the 8s column, so the result is 1000 — that is 8 in decimal.