Skip to content
MoneyDeck

Bitwise Calculator

AND, OR, XOR, NOT and shifts on 8- to 64-bit integers, shown in binary

Updated · Free, no signup

Decimal, 0x hex, 0b binary or 0o octal. Negative decimals use two’s complement.

Result (unsigned decimal)

10

Result (signed, two’s complement)

10

Hexadecimal

0x0A

Binary

0000 1010

Octal

0o12

Expression

202 & 15 = 10

Bits set to 1 (popcount)

2

Bit-by-bit view

RowBinaryHexDecimal
a1100 10100xCA202
b0000 11110x0F15
result0000 10100x0A10

About the Bitwise Calculator

This bitwise calculator applies a logical operation to every bit of two integers and shows the answer in decimal, signed decimal, hexadecimal, octal and binary. Type the operands in decimal, hex (0xFF), binary (0b1010) or octal (0o17) — negative decimals are stored in two’s complement — then pick AND, OR, XOR, NOT, NAND, NOR, XNOR or a left, arithmetic-right or logical-right shift.

It is meant for programmers working with flags and bit masks, permissions, network masks, hardware registers, hashing and compression code, and for students learning how binary logic works. The bit table lines up both operands and the result column by column so you can see exactly which bits were set, cleared or flipped.

Choose a word size of 8, 16, 32 or 64 bits. Every value is truncated to that width, just as a fixed-size integer in C, Java, Rust or Go would be, so NOT 0 in 8 bits is 255 (or −1 signed) rather than an infinite string of ones.

How to use the bitwise calculator

  1. 1Enter value a in decimal, hex (0x…), binary (0b…) or octal (0o…).
  2. 2Choose the operation: AND, OR, XOR, NOT, NAND, NOR, XNOR or a shift.
  3. 3Enter value b, or the number of positions to shift.
  4. 4Pick the word size that matches your language or hardware register.
  5. 5Read the result in decimal, signed, hex and binary, and check the bit table.

Formula and method

AND: 1 only if both bits are 1 · OR: 1 if either is 1 · XOR: 1 if they differ · NOT: flip · a << n = a × 2ⁿ mod 2ʷ · a >>> n = ⌊a ÷ 2ⁿ⌋

Bitwise operators work on each bit position independently. Both operands are first reduced to the chosen word size w by keeping their low w bits (negative numbers become their two’s-complement pattern). AND keeps a bit only where both inputs have a 1, OR sets it where either has a 1, and XOR sets it where the bits differ. NOT flips every bit, and NAND, NOR and XNOR are the inverted forms of AND, OR and XOR.

A left shift by n moves every bit n places towards the most significant end and fills with zeros, which multiplies by 2ⁿ and discards anything that overflows the word. A logical right shift (>>>) fills from the left with zeros, dividing an unsigned value by 2ⁿ and rounding down. An arithmetic right shift (>>) copies the sign bit instead, so negative signed numbers stay negative. The signed result reads the final bit pattern as a two’s-complement number: if the top bit is 1 it equals the unsigned value minus 2ʷ.

w
Word size in bits (8, 16, 32 or 64)
n
Shift amount in bit positions
2ʷ
Number of distinct values a w-bit word can hold

Worked examples

Masking the low nibble: 0b11001010 AND 0x0F

0b11001010 is 202 and 0x0F is 00001111. AND keeps only the bits that are 1 in both, so the high nibble is cleared and the low nibble 1010 survives: the result is 10 (0x0A), with two bits set.

XOR toggle in 32 bits

XOR with all ones flips every bit, which is the same as NOT. 0xDEADBEEF (3,735,928,559) becomes 0x21524110, which is 559,038,736 — together they add up to 4,294,967,295, the largest 32-bit value.

NOT 0 in 8 bits

Flipping all eight zero bits gives 11111111. Read as unsigned that is 255; read as a signed byte in two’s complement it is −1.

Arithmetic right shift of a negative number

−20 in 16-bit two’s complement is 0xFFEC. An arithmetic shift right by 2 keeps the sign bit, giving 0xFFFB, which is −5 signed (−20 ÷ 4) or 65,531 unsigned. A logical shift (>>>) would give 16,379 instead.

Frequently asked questions

What does XOR do?+

XOR (exclusive or) outputs 1 where the two input bits are different and 0 where they are the same. XOR-ing with a mask toggles those bits, and XOR-ing a value with itself always gives 0, which is why it is used in checksums, simple ciphers and swap tricks.

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

Both shift bits to the right. >> is an arithmetic shift that copies the sign bit into the vacated positions, so negative numbers stay negative. >>> is a logical shift that always fills with zeros, treating the value as unsigned. Java and JavaScript have both; C and C++ use >> for both, depending on the type.

Why does NOT 5 give −6?+

NOT flips every bit. In two’s complement, flipping all bits of x gives −x − 1, so ~5 = −6. As an unsigned 8-bit value the same pattern 11111010 is 250.

How do I check whether a bit is set?+

AND the value with a mask that has only that bit set: (value & (1 << n)) != 0. To set a bit use value | (1 << n), to clear it use value & ~(1 << n), and to toggle it use value ^ (1 << n).

Is a left shift the same as multiplying by 2?+

Shifting left by n multiplies by 2ⁿ as long as no 1 bits fall off the top of the word. Once they do, the result wraps around modulo 2ʷ, and for signed types the sign can flip.

How are negative numbers represented?+

Almost all modern hardware uses two’s complement: a negative number −x is stored as 2ʷ − x. In 8 bits, −1 is 11111111 and −128 is 10000000. This calculator converts negative decimal inputs to that pattern before operating.

Related tools