StringMash.com

Bitwise calculator

AND, OR, XOR and NOT on decimal, hex or binary numbers, one bit at a time.

11 characters
Updates as you type
Decimal192
HexC0
Binary1100 0000

Show the steps
  1. Line the bits up. AND gives 1 only where both bits are 1.
  2. 1100 0000
  3. AND 1111 1111
  4. = 1100 0000

Using the calculator

Type two numbers with an operator between them: `192 AND 255`, `12 | 10`, `F0 XOR FF`, or `NOT 15` on its own. Numbers are in tells it which base you're typing, and the answer comes back in decimal, hex and binary. The working lines up the bits so each result bit sits under the two it came from.

The symbols programmers use work too: `&` for AND, `|` for OR, `^` for XOR and `~` for NOT. NOT needs a width, since it flips every bit, so set Bits to the size of the number you mean. NOT 15 is 240 in 8 bits and 65,520 in 16.

AND, OR and NOT

AND gives 1 only where both bits are 1, which makes it a filter. AND with a mask keeps the bits where the mask has 1s and clears the rest. `12 AND 10` is 1100 AND 1010, which is 1000, or 8.

OR gives 1 where either bit is 1, so OR with a mask switches bits on. NOT flips every bit. NAND and NOR are AND and OR followed by NOT. Either one alone is enough to build every other logic gate.

Every subnet mask is an AND

The commonest AND in the world happens every time a computer decides whether an address is on its own network. It ANDs the address with the subnet mask and keeps the network part. 192.168.1.10 AND 255.255.255.0 is 192.168.1.0, because the mask's 1s keep the first 24 bits and its 0s clear the last 8. The subnet calculator shows that AND written out across all 32 bits.

Questions

What is bitwise AND?

An operation on two numbers that gives 1 in each bit position where both numbers have a 1, and 0 everywhere else. 12 AND 10 is 8.

What's the difference between AND and &&?

& (bitwise AND) works on every bit of two numbers. && (logical AND) in most languages treats each side as true or false and gives a single true or false.

Why does NOT give such a big number?

NOT flips every bit in the width you choose, including the zeros in front. NOT 15 in 32 bits is 4,294,967,280.

Can I use negative numbers?

Not directly. Write the two's complement pattern instead, like FFFFFFF0 for −16 in 32 bits.

Sources

Added . What's new