Add, subtract, multiply and divide binary numbers, use bitwise AND, OR and XOR, and convert between binary and decimal, with the working shown.
Working
Works with whole numbers of any length using exact arithmetic. Negative numbers can be entered with a minus sign. Division gives the whole-number quotient and the remainder. AND, OR and XOR compare the bits of non-negative numbers.
A binary calculator adds, subtracts, multiplies and divides binary numbers, performs bitwise AND, OR and XOR, and converts between binary and decimal, showing the working for each step. It handles whole numbers of any length with exact arithmetic and also shows every result in hexadecimal and octal.
For example, 1011 + 110 = 10001 in binary, which is 11 + 6 = 17 in decimal. 101 × 11 = 1111 (5 × 3 = 15). The binary number 101101 equals 45 in decimal, and 255 in decimal is 11111111 in binary.
Binary is a base-2 number system that uses only two digits, 0 and 1. Each position is worth twice the one to its right: 1, 2, 4, 8, 16, 32 and so on, just as each position in decimal is worth ten times the one to its right. Computers use binary because their circuits have two states, off and on, which map naturally to 0 and 1. Each binary digit is called a bit, and 8 bits make a byte.
Multiply each digit by its place value, a power of 2, and add up the results. For 101101:
| Digit | 1 | 0 | 1 | 1 | 0 | 1 |
|---|---|---|---|---|---|---|
| Place value | 32 | 16 | 8 | 4 | 2 | 1 |
32 + 8 + 4 + 1 = 45. Only the positions with a 1 count.
Divide the number by 2 repeatedly and write down each remainder. Then read the remainders from the last one to the first. For 45:
Reading from bottom to top gives 101101.
Binary addition follows four simple rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10, which means write 0 and carry 1. Also, 1 + 1 + 1 = 11: write 1 and carry 1. Adding 1011 and 110 column by column from the right gives 10001.
The rules are 0 − 0 = 0, 1 − 0 = 1, 1 − 1 = 0, and 0 − 1 = 1 with a borrow from the next column. 1011 − 110 = 101, which is 11 − 6 = 5. Computers usually subtract by adding the two’s complement of the second number, which lets the same circuit handle addition and subtraction.
Binary multiplication is like long multiplication in decimal, but simpler: each row is either a copy of the first number (when the digit is 1) or all zeros (when it’s 0), shifted left one place per row. 101 × 11 = 101 + 1010 = 1111.
Binary long division works like decimal long division. 1101 ÷ 11 is 13 ÷ 3, which is 4 remainder 1, or 100 remainder 1 in binary. The calculator shows both the quotient and the remainder.
Bitwise operations compare two numbers bit by bit, and they’re widely used in programming, networking and digital electronics.
Long binary numbers are hard to read, so programmers often use hexadecimal (base 16) or octal (base 8). Each hexadecimal digit stands for exactly four bits, and each octal digit for three. 1111 1111 in binary is FF in hexadecimal and 377 in octal, all equal to 255. The calculator groups binary results into blocks of four to make the link with hexadecimal easy to see.
| Decimal | Binary | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 5 | 0101 | 5 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 15 | 1111 | F |
| 16 | 1 0000 | 10 |
| 255 | 1111 1111 | FF |
Counting in binary works just like counting in decimal, except you run out of digits after 1. The sequence goes 0, 1, 10, 11, 100, 101, 110, 111, 1000, and so on. Each time every digit is 1, the next number adds a new place on the left, just as 999 is followed by 1000 in decimal. With n bits you can count from 0 to 2ⁿ − 1: 4 bits reach 15, 8 bits reach 255 and 16 bits reach 65,535.
This calculator shows negative results with a minus sign, such as −101 for −5. Inside a computer, negative numbers are usually stored using two’s complement. To find the 8-bit two’s complement of 5 (0000 0101), flip every bit to get 1111 1010, then add 1 to get 1111 1011, which represents −5. The advantage is that the computer can subtract by simply adding: 0000 1011 (11) + 1111 1011 (−5) = 0000 0110 (6), ignoring the carry out of the top bit.
Binary can represent fractions too, using places to the right of a binary point worth ½, ¼, ⅛ and so on. 0.101 in binary is ½ + ⅛ = 0.625. Some simple decimals, such as 0.1, can’t be written exactly in binary and repeat forever, which is why computers sometimes show tiny rounding errors such as 0.1 + 0.2 = 0.30000000000000004. This calculator works with whole numbers to keep every result exact.
Because computers work in binary, memory sizes come in powers of 2. A kibibyte (KiB) is 2¹⁰ = 1,024 bytes, a mebibyte (MiB) is 2²⁰ = 1,048,576 bytes and a gibibyte (GiB) is 2³⁰ = 1,073,741,824 bytes. Storage manufacturers usually use decimal units instead, where a gigabyte is 1,000,000,000 bytes, which is why a “500 GB” drive shows as about 465 GiB on many computers.
For related questions, use the hex calculator to do hexadecimal arithmetic and convert hex to decimal, or the scientific notation calculator to convert numbers to and from scientific notation.
Multiply each digit by its place value (1, 2, 4, 8, …) from the right and add the results. 101101 = 32 + 8 + 4 + 1 = 45.
Divide by 2 repeatedly, note each remainder, then read the remainders from last to first. 45 becomes 101101.
Add column by column from the right: 0 + 0 = 0, 0 + 1 = 1, and 1 + 1 = 10 (write 0, carry 1). 1011 + 110 = 10001.
11111111, which is eight 1s in a row. It's the largest number that fits in one byte, and FF in hexadecimal.
A bit is a single binary digit, 0 or 1. A byte is 8 bits and can represent 256 different values, from 0 to 255.
It gives 1 where the two bits differ and 0 where they're the same. 1100 XOR 1010 = 0110.
Usually by adding the two's complement of the second number, which is found by inverting its bits and adding 1.
Yes. The calculator uses exact whole-number arithmetic, so long binary numbers are handled without any rounding, however many digits they have.
255, written 11111111. With n bits, the largest unsigned value is 2ⁿ − 1.
0, 1, 10, 11, 100, 101, 110, 111, 1000. When every digit is 1, the next number adds a new place on the left.
A way to store negative numbers: flip every bit of the positive number and add 1. In 8 bits, −5 is 11111011.
No. 0101 and 101 both equal 5. Leading zeros are often added to fill a fixed number of bits.
Each hexadecimal digit represents exactly four bits, so long binary numbers can be written much more compactly.