Binary Calculator

Type two binary numbers, choose + − × ÷ and read the answer in binary, decimal, hexadecimal and octal. Below it, convert any binary number to decimal or any decimal number to binary, with the place-value table that shows how.

How it is calculated

Type the first binary number using only 0 and 1.

Choose the operation.

Type the second binary number.

Read the result in binary, decimal, hex and octal.

Formula

Place values: … 2⁴ = 16, 2³ = 8, 2² = 4, 2¹ = 2, 2⁰ = 1

Addition rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1)

Binary to decimal: Add the place values where the bit is 1

Decimal to binary: Divide by 2 repeatedly; read the remainders from last to first

What is the Binary Calculator?

Binary is the base-2 number system: it uses only the digits 0 and 1, and each place is worth twice the place to its right. The binary calculator adds, subtracts, multiplies or divides two binary numbers and shows the answer in binary, decimal, hexadecimal and octal. Two converters below it change binary to decimal and decimal to binary.

It is meant for students of computer science and digital electronics, and for anyone working with networks, where IP addresses and subnet masks are binary numbers written in a shorter form. The place-value table and the divide-by-2 table show exactly how each conversion is done, so the tool can be used to check homework as well as to get a quick answer. Numbers up to 256 bits are handled without rounding.

How to calculate it by hand

1. Write the two binary numbers one under the other, lined up on the right.

2. To add, work from the right: 1 + 1 is 10, so write 0 and carry 1.

3. To subtract, borrow from the next column when taking 1 from 0; the borrowed 1 is worth 2.

4. To multiply, write a shifted copy of the first number for every 1 in the second, then add the copies.

5. To divide, use long division with binary subtraction.

6. Check by converting both numbers and the answer to decimal.

Place value in base 2

In decimal, the places are worth 1, 10, 100 and so on, each ten times the last. In binary they are worth 1, 2, 4, 8, 16, each twice the last. The number 10111 therefore means one 16, no 8, one 4, one 2 and one 1, which is 23. To go the other way, divide the decimal number by 2 again and again and note the remainders; reading them from last to first gives the binary digits.

Why computers count in binary

An electronic circuit can tell two states apart very reliably: a voltage that is low or high, a switch that is off or on. Telling ten different levels apart would need far more precise and costly parts. So computers store everything as bits, and group them: 8 bits make a byte, which can hold 256 different values. Hexadecimal is used as shorthand because one hex digit stands for exactly four bits.

Binary in networking

An IPv4 address is 32 bits written as four decimal numbers, each standing for 8 bits. A subnet mask such as 255.255.255.0 is 24 ones followed by 8 zeros, and combining it with an address using a bit-by-bit AND gives the network address. Being able to read 192 as 11000000 or 240 as 11110000 is the skill behind subnetting, which is why binary conversion is practised so much in networking courses.

Worked example, step by step

A student in a digital electronics class needs to add the binary numbers 1011 and 110 and check the answer in decimal.

Read the first number in decimal: 1011 = 8 + 2 + 1 = 11

Read the second number in decimal: 110 = 4 + 2 = 6

Do the sum in decimal: 11 + 6 = 17

Write the answer in binary: 17 = 10001

Answer: Result in binary 0001 0001; In decimal 17; In hexadecimal 11

Common mistakes to avoid

Forgetting a carry when a column is 1 + 1 plus a carried 1, which gives 1 and another carry.

Reading place values from the left instead of from the right.

Dropping a zero at the right-hand end of a number, which halves its value.

Typing a digit other than 0 or 1.

Reading the divide-by-2 remainders from top to bottom instead of bottom to top.

Where it is used

Checking binary arithmetic homework in computer science and electronics.

Converting between binary and decimal for subnetting and IP addressing.

Understanding bit masks, flags and file permissions in programming.

Preparing for exam questions on number systems.

Reading register values and data sheets in embedded work.

Frequently asked questions

How do you add binary numbers?

Add column by column from the right. 1 + 1 is 10 in binary, so write 0 and carry 1 to the next column. 1 + 1 + 1 is 11: write 1 and carry 1.

How do I convert binary to decimal?

Write the place values 1, 2, 4, 8, 16 … from the right, and add the ones that sit under a 1. For 10111 that is 16 + 4 + 2 + 1 = 23.

How do I convert decimal to binary?

Keep dividing by 2 and note each remainder. Read the remainders from the last one to the first. 18 gives 10010.

What happens if the subtraction goes below zero?

The result is shown with a minus sign. Computers store negative numbers differently, using two's complement.