A binary calculator does arithmetic directly in base 2. This one adds, subtracts, multiplies and divides binary numbers, and also performs the bitwise operations programmers use every day: AND, OR, XOR, NOT and shifts. Results can be exact, at any size, or wrapped to a fixed 8, 16, 32 or 64-bit width like a real processor, with carries and overflow flagged. Here's how each operation works, so you can follow the working the calculator shows.
Binary addition
Binary addition follows the same column method as decimal, with simpler rules. 0 + 0 = 0, 0 + 1 = 1 and 1 + 1 = 10, which means write 0 and carry 1. With a carry coming in, 1 + 1 + 1 = 11, so you write 1 and carry 1. Add 1011 (11) and 110 (6) from right to left: 1 + 0 = 1, 1 + 1 = 0 carry 1, 0 + 1 + 1 = 0 carry 1, and 1 + 1 = 0 carry 1. The final carry becomes a new leftmost digit, giving 10001, which is 17.
Binary subtraction
Subtraction by hand also works column by column, borrowing when you need to take 1 from 0. 1011 − 110 gives 101, which is 11 − 6 = 5. Processors take a different route: they add the two's complement of the second number. In 8 bits, 6 is 00000110 and −6 is 11111010. Adding 00001011 + 11111010 gives 1 00000101, and dropping the carry leaves 00000101, or 5. Choose a fixed width in this binary calculator to see results stored that way. The two's complement calculator explains the negative patterns in more detail.
Binary multiplication
Multiplying in binary is easier than in decimal, because each digit of the multiplier is either 0 or 1. For every 1, write the other number shifted left by that position, then add the rows. For 101 × 11, the rows are 101 and 1010, and their sum is 1111. That's 5 × 3 = 15. This shift-and-add method is how simple processors multiply, and it's why multiplying by a power of two is just a shift.
Binary division
Binary long division works like decimal long division, except each step only asks whether the divisor fits, so every quotient digit is 0 or 1. 10111 ÷ 101 gives a quotient of 100 and a remainder of 11, which is 23 ÷ 5 = 4 remainder 3. This calculator always returns a whole-number quotient and the remainder, the same way integer division works in most programming languages. Dividing by zero shows an error.
Bitwise operations: AND, OR, XOR and NOT
Bitwise operations compare numbers one bit at a time, with no carrying. They're the basis of bit masks, flags and many fast algorithms:
- AND gives 1 only where both bits are 1. It's used to test or clear bits:
11010110AND00001111keeps just the low four bits,00000110. - OR gives 1 where either bit is 1. It's used to set bits:
10000000OR00000001gives10000001. - XOR gives 1 where the bits differ. It's used to toggle bits:
11110000XOR10101010gives01011010. XOR with the same value twice returns the original number. - NOT flips every bit of a single number. In a fixed width, NOT x equals −x − 1 when read as a signed value.
Shifts
A left shift moves every bit toward the high end and fills in zeros on the right. Each place multiplies the value by 2, so 101 shifted left by 2 is 10100, or 5 × 4 = 20. A right shift moves the bits the other way, dividing by 2 for each place and dropping the remainder. In a fixed width, bits shifted past the edge are lost, and this binary calculator flags when that happens. Right shifts here are logical, filling the left with zeros. In Auto mode, a negative number shifted right rounds down, like an arithmetic shift.
Fixed widths, carry and overflow
Real processors work with registers of a fixed size. In 8-bit mode, the calculator keeps every input and result in 8 bits. A result that's too big for the unsigned range wraps around and is flagged as Carry out: 11111111 + 1 gives 00000000. A result outside the signed range is flagged as Signed overflow: 01111111 + 1 gives 10000000, which reads as −128. Seeing both flags side by side shows why the same addition can be correct as unsigned and wrong as signed.
Getting reliable results
- Use Auto for exact answers of any size, and a fixed width to imitate a specific data type.
- Type negative numbers with a minus sign. Bitwise operations on negative numbers need a fixed width, because the answer depends on how many bits are used.
- Use Use result as A to chain calculations, and Swap A and B to reverse an operation.
- To read the result in other bases, try the binary to decimal converter or the binary to hex converter.
To double-check a result, convert both inputs to decimal, do the sum there, and convert back. The binary to decimal converter makes that a few seconds' work.