Bitwise Calculator (AND, OR, XOR, Shift)

Apply AND, OR, XOR, NOT, NAND, NOR, XNOR, shifts and rotates to 8- to 64-bit integers entered in binary, decimal, hex or octal, with signed and unsigned results.

Bit width
Negative decimal numbers are stored in two’s complement.
Binary
1000 1000
Hexadecimal
0x88
Octal
0o210
Unsigned decimal
136
Signed decimal
−1208-bit two’s complement
Bits set (popcount)
2
A AND B =1000 10000x88 · 136 unsigned · −120 signed

Show the work

  1. AND gives 1 only where both bits are 1. It is used to mask (keep) selected bits.
  2. A = 1100 1010, B = 1010 1100
  3. Result = 1000 1000 = 0x88 = 136 unsigned = −120 signed

Bit by bit (8-bit, 1-bits highlighted)

A11001010202
B10101100172
A AND B10001000136
Every two-input operation for A = 202 and B = 172
OperationBinaryHexUnsignedSigned
AND1000 10000x88136−120
OR1110 11100xEE238−18
XOR0110 01100x66102102
NAND0111 01110x77119119
NOR0001 00010x111717
XNOR1001 10010x99153−103

Bitwise operations work on the individual bits of integers, and they are everywhere in low-level and systems code: masking flags, packing colors into a 32-bit pixel, building checksums, computing subnet addresses, speeding up multiplication by powers of two. This calculator applies any common bitwise operation to values from 8 to 64 bits wide, accepts input in binary, decimal, hex or octal, and draws the bits of both operands and the result in aligned rows so you can see exactly what happened.

How to use the bitwise calculator

  1. Pick the bit width: 8, 16, 32 or 64. Results wrap to this width, as they would in a fixed-size register.
  2. Choose how the numbers are written: binary, decimal, hexadecimal or octal. Negative decimal values are stored in two’s complement.
  3. Choose the operation. AND, OR, XOR, NAND, NOR and XNOR use A and B; NOT uses only A; shifts and rotates use A and Shift by.
  4. Read the result in binary, hex, octal, unsigned and signed decimal, and the number of 1-bits. For two-input operations a table lists all six results side by side.

Truth table

A B AND OR XOR NAND NOR XNOR
0 0 0 0 0 1 1 1
0 1 0 1 1 1 0 0
1 0 0 1 1 1 0 0
1 1 1 1 0 0 0 1

Shifts move every bit sideways:

A << n = A × 2n (mod 2width)  ·  A >>> n = ⌊A ÷ 2n⌋

A rotate is a shift in which the bits that fall off one end re-enter at the other, so no information is lost.

Worked example

With 8-bit values A = 11001010 (202) and B = 10101100 (172):

AND: 1 only where both are 1 → 10001000 = 136 (0x88).

OR: 1 where either is 1 → 11101110 = 238 (0xEE).

XOR: 1 where they differ → 01100110 = 102 (0x66).

NOT A: flip every bit → 00110101 = 53.

A << 3: 11001010 shifted left 3 = 01010000 = 80. Three 1-bits fell off the top, so this is not 202 × 8 = 1,616 — the result overflowed the 8-bit width.

A signed shift: −100 in 8-bit two’s complement is 10011100. An arithmetic right shift by 2 gives 11100111 = −25, the same as −100 ÷ 4.

Everyday bit tricks

Task Expression Example (8-bit)
Keep low 4 bits x AND 0x0F 0xCA → 0x0A
Set bit 3 x OR 0x08 0x01 → 0x09
Clear bit 3 x AND NOT 0x08 0x0F → 0x07
Toggle bits x XOR mask 0xCA XOR 0xFF → 0x35
Is x even? x AND 1 = 0 202 AND 1 = 0 → even
Is x a power of 2? x AND (x − 1) = 0 64 AND 63 = 0 → yes

XOR has a special property: applying the same mask twice restores the original (x XOR k XOR k = x). Simple checksums, RAID parity and many ciphers rely on it.

Width and sign

The same bit pattern means different numbers depending on whether you read it as unsigned or signed. In 8 bits, 10001000 is 136 unsigned but −120 in two’s complement. That is why the tape shows both, and why language rules differ: Java and JavaScript have a separate >>> operator, while C and C++ choose the shift type from the operand’s declared signedness.

To see two’s complement encoding step by step, use the two’s complement calculator. For ordinary arithmetic in base 2, try the binary calculator, and to apply AND masks to IP addresses, the subnet calculator.

Frequently asked questions

What does a bitwise AND do?

It compares two numbers bit by bit and outputs 1 only where both bits are 1. It is used to mask bits: x AND 0x0F keeps the low four bits of x and clears the rest. Network masks work the same way, which is how a router finds a subnet address.

What is the difference between >> and >>>?

Both shift bits to the right. An arithmetic shift (>> in C-family languages for signed types) copies the sign bit into the vacated positions, so negative numbers stay negative. A logical shift (>>> in Java and JavaScript) fills with zeros, treating the value as unsigned.

Why does NOT 5 give a large number or a negative one?

NOT flips every bit within the chosen width. In 8 bits, 5 is 00000101 and NOT 5 is 11111010, which is 250 unsigned or −6 signed. The calculator shows both readings.

How do I toggle, set or clear a single bit?

To set bit n, OR with 1 << n. To clear it, AND with NOT (1 << n). To toggle it, XOR with 1 << n. To test it, AND with 1 << n and check for a nonzero result.

Last reviewed October 2026 by the CalcFluent editorial team. How we check our calculators.