Binary Calculator

Binary sums work like decimal ones, with only 0 and 1. In 1011 + 110 = 10001 each 1 + 1 writes 0 and carries 1, and in decimal it is 11 + 6 = 17 (see it in columns). The calculator also subtracts, multiplies, divides and runs AND, OR, XOR, NOT and shifts, and shows the working for each step.

Calculate with binary numbers

Type two binary numbers and pick an operation. The answer is written out in columns, and it updates as you type.

Bit width
Examples:

How to Use This Calculator

  1. Type two binary numbers

    Use only 0 and 1. Spaces, underscores and a 0b prefix are ignored, and the decimal value shows under each field.

  2. Pick the operation

    Choose +, −, ×, ÷, AND, OR, XOR, NOT or a shift. Set a bit width of 8, 16 or 32 to see overflow and two's complement.

  3. Follow the columns

    The answer appears as you type, with the sum written out in columns, every carry or borrow, and the steps in words.

How binary numbers work

Binary, or base 2, writes every number with two digits, 0 and 1. Each digit is called a bit. In decimal each place is worth ten times the one to its right (1, 10, 100). In binary each place is worth twice as much: 1, 2, 4, 8, 16, 32 and so on. A 1 in a place means that value is counted, and a 0 means it is not.

Place values of the binary number 1011
Place value 8 4 2 1 Total
Bit 1 0 1 1
Counted 8 0 2 1 = 11

So 1011 in binary is 8 + 0 + 2 + 1 = 11 in decimal. To go the other way, divide by 2 again and again and write down the remainders: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Read the remainders from the bottom up and you get 1101. Here are the numbers from 0 to 16:

Decimal numbers 0 to 16 in binary and hexadecimal
Decimal Binary Hex
0 0 0
1 1 1
2 10 2
3 11 3
4 100 4
5 101 5
6 110 6
7 111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
16 10000 10

How to add binary numbers

Write the numbers one under the other, lined up on the right, and add each column starting from the right. There are only four cases to remember:

Addition rules
0 + 0 = 00 + 1 = 11 + 1 = 101 + 1 + 1 = 11
10 means write 0 and carry 1 into the next column; 11 means write 1 and carry 1.

For 1011 + 110:

  1. The 1s column: 1 + 0 = 1. Write 1.
  2. The 2s column: 1 + 1 = 10. Write 0, carry 1.
  3. The 4s column: 0 + 1 + the carry = 10. Write 0, carry 1.
  4. The 8s column: 1 + 0 + the carry = 10. Write 0, carry 1.
  5. The last carry becomes a new digit on the left. The sum is 10001, which is 11 + 6 = 17.

Show 1011 + 110 with the carries

To add three or more numbers, add two of them and then add the next number to that total. For 101 + 11 + 1100 + 11101: 101 + 11 = 1000, then + 1100 = 10100, then + 11101 = 110001, which is 49.

How to subtract binary numbers

Subtraction also goes column by column from the right. 1 − 0 = 1, 1 − 1 = 0 and 0 − 0 = 0. When a column asks for 0 − 1, borrow 1 from the next column to the left. In binary that borrowed 1 is worth 2 in the current column, so 0 − 1 becomes 10 − 1 = 1, and the column you borrowed from goes down by 1. If that column is 0 as well, the borrow moves further left until it finds a 1.

1000000 − 101101 is a good test because nearly every column borrows. The answer is 10011, which matches 64 − 45 = 19 in decimal.

Show 1000000 − 101101 with the borrows

When the second number is larger, the answer is negative. Written by hand, you subtract the smaller from the larger and put a minus sign in front: 101 − 111 = −10, which is 5 − 7 = −2. Computers store a negative number as two's complement instead, which is explained under bit widths below.

Binary multiplication

Multiplying in binary is easier than in decimal, because each digit of the second number is either 0 or 1. For every 1, write the first number shifted left by that digit's position; for every 0, write a row of zeros. Then add the rows. For 1101 × 101 the rows are 1101 and 110100 (1101 shifted two places), and their sum is 1000001. In decimal that is 13 × 5 = 65.

Show 1101 × 101 with the partial products

Binary division

Binary long division follows the same pattern as decimal long division, with an easier question at each step: does the divisor fit, yes or no? Bring down the digits of the first number one at a time. When the number so far is at least the divisor, write 1 in the answer and subtract; otherwise write 0. 11011 ÷ 11 = 1001 with nothing left over (27 ÷ 3 = 9). 1101 ÷ 100 = 11 remainder 1 (13 ÷ 4 = 3 remainder 1).

Show 11011 ÷ 11 one digit at a time

AND, OR, XOR and NOT

Bitwise operations do not carry or borrow. They compare the two numbers one column at a time and write one bit per column. Programmers use AND to pick out bits with a mask, OR to switch bits on, and XOR to flip bits or compare two values.

Truth table for AND, OR, XOR and NOT
A B A AND B A OR B A XOR B NOT A
0 0 0 0 0 1
0 1 0 1 1 1
1 0 0 1 1 0
1 1 1 1 0 0

For 11001100 and 10101010, AND keeps only the columns where both have a 1, which gives 10001000. OR gives 11101110 and XOR gives 01100110. NOT works on one number and flips every bit, so how many bits you use matters: NOT 101 is 010 in three bits but 11111010 in eight.

Show 11001100 AND 10101010 bit by bit

Shifting bits

A left shift moves every bit toward the left and fills the right with zeros. Each place doubles the value, so 10110 << 2 = 1011000: 22 × 4 = 88. A right shift moves the bits the other way and drops the ones that fall off the end, which halves the value and rounds down.

Show 10110 << 2

Bit widths, overflow and two's complement

Computers store numbers in a fixed number of bits, such as 8, 16 or 32. With n bits there are 2ⁿ possible patterns. Read as unsigned they run from 0 to 2ⁿ − 1, and read as signed two's complement they run from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1.

Unsigned and signed ranges for 4, 8, 16 and 32 bits
Bits Unsigned Signed
4-bit 0 to 15 −8 to 7
8-bit 0 to 255 −128 to 127
16-bit 0 to 65,535 −32,768 to 32,767
32-bit 0 to 4,294,967,295 −2,147,483,648 to 2,147,483,647

Overflow happens when an answer needs more bits than there are. In 8 bits, 200 + 100 = 300 needs a ninth bit. The ninth bit is dropped, so the stored answer is 300 − 256 = 44. Set the bit width to 8 in the calculator and the dropped bit is drawn hatched.

See 200 + 100 overflow in 8 bits

Two's complement is how computers write negative numbers. To get −x in n bits, write x in n bits, flip every bit, and add 1. For −2 in 8 bits: 2 is 00000010, flipped it is 11111101, and adding 1 gives 11111110. In two's complement, ordinary binary subtraction gives the right bits: 5 − 7 in 8 bits gives 11111110, which is −2. The leftmost bit tells you the sign; 1 means negative.

Show 5 − 7 in 8 bits

Binary and hexadecimal

Long binary numbers are hard to read, so programmers often write them in hexadecimal (base 16). Every group of four bits is exactly one hex digit, from 0000 = 0 to 1111 = F. Split the number into fours from the right and convert each group: 1101 0110 is D and 6, so D6. The calculator gives every answer in hexadecimal as well, and spaces the binary digits in groups of four.

Common mistakes

  • Lining the numbers up on the left. Binary numbers line up on the right, at the 1s place, the same as decimal numbers.
  • Writing 2 when a column adds up to two. In binary, 1 + 1 is 10: write 0 and carry 1.
  • Forgetting the carry in the next column, especially when three ones meet (1 + 1 + 1 = 11).
  • Borrowing from a 0. The borrow has to travel left to the nearest 1, turning the 0s it passes into 1s.
  • Mixing up bitwise and ordinary operations. 1 OR 1 is 1, but 1 + 1 is 10.
  • Ignoring the bit width. NOT, overflow and negative numbers all depend on how many bits there are.

Frequently Asked Questions

How do you add binary numbers?

Line the numbers up on the right and add one column at a time, as in decimal. 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 10, so you write 0 and carry 1 to the next column. With a carry, 1 + 1 + 1 = 11: write 1 and carry 1. For example 1011 + 110 = 10001, which is 11 + 6 = 17.

Show 1011 + 110 in columns

What is 1 + 1 in binary?

1 + 1 = 10 in binary. Binary has only the digits 0 and 1, so two ones fill the column: you write 0 and carry 1 into the next place, which is worth 2. That is why 10 in binary means two.

How do you subtract binary numbers?

Subtract column by column from the right. 1 − 0 = 1, 1 − 1 = 0 and 0 − 0 = 0. For 0 − 1 you borrow 1 from the next column, which is worth 2 here, so the column becomes 10 − 1 = 1. For example 1000000 − 101101 = 10011, which is 64 − 45 = 19.

Show 1000000 − 101101 with the borrows

How do you convert binary to decimal?

Multiply each digit by its place value and add the results. From the right the place values are 1, 2, 4, 8, 16 and so on, each double the last. 1011 is 8 + 0 + 2 + 1 = 11. The calculator shows the decimal value of every number under the field you type it in.

What is the largest 8-bit binary number?

The largest 8-bit number is 11111111, which is 255. Eight bits give 2⁸ = 256 different values, from 0 to 255 when unsigned. As a signed two's complement number the same 8 bits hold −128 to 127.

See 200 + 100 overflow in 8 bits

What is the difference between AND, OR and XOR?

All three compare two numbers bit by bit. AND gives 1 only where both bits are 1, OR gives 1 where at least one is 1, and XOR gives 1 where the bits differ. For 11001100 and 10101010, AND gives 10001000, OR gives 11101110 and XOR gives 01100110.

Show 11001100 AND 10101010

How do you divide binary numbers?

Use long division. Bring down the digits of the first number one at a time; when the number so far is at least the divisor, write 1 in the answer and subtract, otherwise write 0. 11011 ÷ 11 = 1001, which is 27 ÷ 3 = 9.

Show 11011 ÷ 11 step by step