Skip to content

Bitwise Calculator

Type two numbers (decimal, 0x hex or 0b binary) and pick an operation to see the result with every bit lined up.

v2026.10.07

Operation

Decimal, 0x hex, 0b binary or 0o octal; negative numbers are two’s complement.

Width

AND, 8 bits

0000 0101

181 & 0x0F = 5 (0x05) in 8 bits.

A
B
=
Decimal
5
Hex
0x05
Signed
5
How this works: Method, 2 sources, Checked against 1 worked example,

How this works

Method

Bitwise operators work on each bit position separately, with no carries between columns. AND gives 1 only where both bits are 1, OR where either is, and XOR where exactly one is. NOT flips every bit of a single number. Full method

How it’s tested

One worked example for this page is checked by automated tests before every release: given the inputs, the tool must show the expected answer.

Privacy

On your device. Nothing you enter or open leaves this browser. About privacy labels

Changes

  • Rebuilt with 18 conversion pages, including text to binary and hex, two’s complement, IEEE 754 floating point, a bitwise calculator and Roman numerals, each with its method and a table.
  • Added key facts with worked examples of converting between bases.
  • Redesigned: the working shown step by step, and the same number in the other common bases under the answer.
  • Fixed large numbers: values above 2^53, such as 64-bit hex, now convert exactly instead of rounding.
  • First published.

Every change on What’s new

How we make toolsReport a mistake

How the bitwise operators work

Bitwise operators work on each bit position separately, with no carries between columns. AND gives 1 only where both bits are 1, OR where either is, and XOR where exactly one is. NOT flips every bit of a single number.

Shifts move the whole pattern. A left shift by n multiplies by 2ⁿ, dropping bits that fall off the top. A logical right shift (>>> in Java and JavaScript) fills from the left with zeros; an arithmetic right shift (>> on signed values) copies the sign bit, so it divides negative numbers by 2ⁿ rounding down.

The width matters for NOT and shifts: NOT 0 is 255 in 8 bits but 4,294,967,295 in 32. Pick the width your language or register uses; JavaScript’s bitwise operators work on 32-bit signed integers.

AND: 1·1 = 1 · OR: 1 if any · XOR: 1 if different · x << n = x × 2ⁿ

Common bit tricks

Patterns used for flags, masks and fast arithmetic, each with an 8-bit example.

Patterns used for flags, masks and fast arithmetic, each with an 8-bit example.
ExpressionWhat it doesExample (8 bits)
x & 1odd test: 1 if x is odd00101101 → 1
x & (x − 1)clear the lowest set bit00101100 → 00101000
x & −xkeep only the lowest set bit00101100 → 00000100
x | (1 << n)set bit n (n = 1)00101100 → 00101110
x & ~(1 << n)clear bit n (n = 2)00101100 → 00101000
x ^ (1 << n)toggle bit n (n = 0)00101100 → 00101101
(x >> n) & 1read bit n (n = 3)00101100 → 1
x & 0x0Fkeep the low nibble10101100 → 00001100
x << 3multiply by 800000101 → 00101000
x >> 2divide by 4, rounding down00101101 → 00001011
Show all 12 rows
x ^ xalways 001101001 → 00000000
~xNOT, equal to −x − 1 when signed00000101 → 11111010

Frequently Asked Questions

What is the difference between & and && ?

& is bitwise AND: it combines two numbers bit by bit (6 & 3 = 2). && is logical AND: it asks whether both values are true and returns a true/false result.

What does XOR do?

It sets a bit where the two inputs differ. XOR-ing with a mask toggles the masked bits, and XOR-ing a value with itself gives 0.

Why does NOT 5 give −6?

NOT flips every bit: 00000101 becomes 11111010, which is −6 when read as a signed (two’s complement) number and 250 when read unsigned. In general ~x = −x − 1.