How to use the binary calculator
- Type the first binary number. Use only the digits 0 and 1. A leading minus sign, a 0b prefix, spaces and underscores are allowed.
- Choose the operation: add, subtract, multiply or divide.
- Type the second binary number.
- Read the result in binary, decimal, hexadecimal and octal. For addition and subtraction the table shows each column with its carry or borrow. Division also shows the remainder.
Formula
each place is worth twice the place to its right: 1, 2, 4, 8, 16 ...
add: column sum = a + b + carry, digit = sum mod 2, carry out = sum div 2
subtract: borrow 2 from the next column when a column goes below 0
divide: quotient and remainder, cut toward zero
Numbers up to 256 binary digits are supported and every result is exact. Negative results keep their minus sign instead of being written in two's complement.
101101 and 1011
101101 is 45 and 1011 is 11. Adding them gives 111000, which is 56 in decimal, 38 in hex and 70 in octal. The column table shows the carries: the lowest column is 1 + 1 = 10, so it writes 0 and carries 1, and the carry travels up through the fourth column.
Subtracting gives 100010 (34), multiplying gives 111101111 (495, hex 1EF), and dividing gives a quotient of 100 (4) with a remainder of 1. Reversing the subtraction, 1011 - 101101, gives -100010, which is -34.
Reading the carry table
Addition works like decimal addition, except a column carries as soon as it reaches 2. The table lists the places from the right, with the two digits, the carry coming in, the digit written and the carry going out. Subtraction works the same way with a borrow of 2 instead of a carry.
The carry out of the last place becomes the leading digit of the result when it is 1, which is why adding two 6-digit numbers can give a 7-digit answer.
Other number tools
To convert between bases without arithmetic, use the number base converter. To see how negative numbers are stored in a fixed number of bits, use the two's complement converter. For AND, OR, XOR and shifts, use the bitwise calculator, and to turn text into binary use the binary translator.
Assumptions and limits
- Numbers are whole integers in base 2. Fractions with a binary point are not accepted.
- Division truncates toward zero, so the remainder has the same sign as the first number.
- Results have no fixed width, so there is no overflow. Fixed-width wraparound is not modeled.
- The column tables are shown for non-negative operands of up to 24 digits, and for subtraction only when the first number is at least the second.
Frequently asked questions
How do you add binary numbers?
Add column by column from the right. 0 + 0 is 0, 0 + 1 is 1, and 1 + 1 is 10, which writes 0 and carries 1 into the next column. The table on this page shows each column, so you can follow the carries.
Can I use negative binary numbers?
Yes, with a leading minus sign. The result keeps its sign, so 1011 - 101101 is -100010. For fixed-width negative values, use the two's complement converter.
What happens when I divide binary numbers?
You get a whole-number quotient and a remainder, both in binary and decimal. Division by zero is refused with a message.
Why does the result also show hex and octal?
Groups of four binary digits map to one hex digit and groups of three to one octal digit, so those forms are shorter ways to write the same value and are common in programming.