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, NAND and NOR flip bits, so they need a width. Bits sets it and starts at 8, the same register the bit shift calculator uses. NOT 15 in 8 bits is 1111 0000. In decimal you get −16 first, as C or Java would print it, and then 240, the same bits read unsigned. In 16 bits the unsigned reading is 65,520.
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 a negative number?
NOT flips every bit in the width you choose, including the zeros in front, so the top bit comes out as 1. Read as a signed number, that top bit means negative. NOT 15 in 32 bits is −16 signed and 4,294,967,280 unsigned, and the calculator shows both.
Can I use negative numbers?
Yes. A negative number is taken as its two's-complement pattern in the Bits width, so −16 is 1111 0000 in 8 bits and FFFFFFF0 in 32. In 8 bits, −16 AND 255 keeps all eight of those bits. A number too big for the width gets an error, never a quietly cut-off answer.
Sources
Added . Last updated and reviewed . What's new






