Binary Calculator
Type two binary numbers and get the sum, difference, product or quotient — with the carries, borrows, partial products and long-division steps laid out column by column. Switch to bitwise mode to apply AND, OR, XOR, NOT, shifts and rotates at 4 to 128 bits. Free, no sign-up, and nothing leaves your browser.
Binary digits only, with an optional leading minus. Spaces and underscores are ignored, so 1011 0110 works.
Result
1 0010
Binary
18
Decimal
12
Hexadecimal
22
Octal
5 bits
Length
Working
| Row | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|
| Carry in | 1 | 1 | 0 | 1 | 0 |
| A | 0 | 1 | 1 | 0 | 1 |
| B | 0 | 0 | 1 | 0 | 1 |
| Sum | 1 | 0 | 0 | 1 | 0 |
How to Use the Binary Calculator
- 1. Pick the kind of operation. Arithmetic adds, subtracts, multiplies or divides. Bitwise works on the individual bits of fixed-width patterns.
- 2. Enter your numbers. Use only 0 and 1. A leading minus, a
0bprefix, spaces and underscores are all fine, so1011 0110reads as one number. - 3. Choose a width (bitwise only). NOT, shifts and rotations mean nothing without a width, so the calculator asks for one: 4, 8, 16, 32, 64 or 128 bits.
- 4. Read the result and the working. The answer appears in binary, decimal, hexadecimal and octal, with the column working underneath.
How Binary Addition Works
Binary addition follows the same column rules as decimal addition, but a column overflows at 2 instead of 10. Add the two bits in a column plus any carry that arrived from the right. If the total is 0 or 1, write it down. If it is 2 or 3, write the low bit (0 or 1) and carry 1 into the next column.
| Column total | Bit written | Carry out |
|---|---|---|
| 0 + 0 + 0 = 0 | 0 | 0 |
| 1 + 0 + 0 = 1 | 1 | 0 |
| 1 + 1 + 0 = 10 (2) | 0 | 1 |
| 1 + 1 + 1 = 11 (3) | 1 | 1 |
Take 1101 (13) plus 101 (5). The calculator pads both to five columns and shows the carry arriving into each one — 11010 from left to right — giving 10010, which is 18. The carry row is the part people lose when they add by hand.
Subtraction, Multiplication and Division
Subtraction works the other way round: when a column needs 1 − 1 − 1 or 0 − 1, it borrows 1 from the column on its left, which is worth 2 here. 1000 − 0011 shows a borrow rippling through three columns and ends at 0101 (8 − 3 = 5). When A is smaller than B, the calculator subtracts the smaller from the larger and gives the result a minus sign.
Multiplication is shift and add. Every 1 in the multiplier contributes a copy of the multiplicand shifted left by that bit's position, and a 0 contributes nothing. For 1011 × 101 (11 × 5), the 1s sit at positions 0 and 2, so the partial products are 1011 and 101100, and their sum is 110111 — 55.
Division is long division with a very easy guessing step. Bring down one bit of the dividend at a time; if the divisor fits into what you have, subtract it and write a 1 in the quotient, otherwise write a 0. 1100100 ÷ 111 (100 ÷ 7) gives a quotient of 1110 (14) and a remainder of 10 (2). With negative operands, the quotient truncates toward zero and the remainder takes the sign of A, as in C, Java and JavaScript.
Bitwise Operations at a Chosen Width
| A | B | AND | OR | XOR | NAND | NOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
With 1100 and 1010 at 4 bits, AND gives 1000, OR gives 1110 and XOR gives 0110. NOT flips every bit inside the width, so the same 1100 becomes 0011 at 4 bits but 11110011 at 8 bits — which is why the width matters.
A left shift by n moves every bit n places up and fills with zeros; the bits that fall off the top are lost, and the calculator lists them. A logical right shift fills with zeros. An arithmetic right shift copies the top bit, so a negative number stays negative: 10110110 shifted right by 2 is 00101101 logically but 11101101 (−19) arithmetically. Rotations wrap the bits that fall off one end back onto the other, so nothing is lost.
No overflow in arithmetic mode
Arithmetic here is exact at any length, so 11111111 + 1 is 100000000, not 0. Real hardware keeps a fixed number of bits and wraps around. To see that behaviour — and the signed ranges that go with it — use the Two's Complement Calculator.
Common Mistakes
- Forgetting the carry into the leftmost column. Adding two 8-bit numbers can produce a 9-bit answer. The calculator keeps the extra column.
- Mixing up logical and arithmetic right shifts. They agree for positive numbers and disagree for any pattern whose top bit is 1. Languages differ: Java's
>>is arithmetic and>>>is logical, while C leaves>>on a negative signed value up to the compiler (arithmetic on mainstream ones). - Reading a bit pattern as a signed number by accident.
11110011is 243 unsigned and −13 in two's complement. The bitwise results show both so you can tell which one you mean. - Assuming NOT is width-free. In an unbounded integer, NOT of 12 is −13. Inside a fixed width it is the complement pattern, which is what this calculator returns.
Frequently Asked Questions
- How do you add binary numbers?
- Work from the rightmost column to the left, adding the two bits and any carry. A column total of 0 or 1 is written as is; a total of 2 is written as 0 with a carry of 1, and a total of 3 as 1 with a carry of 1. For example, 1101 + 101 = 10010. The calculator shows the carry into every column.
- How do you subtract binary numbers?
- Subtract column by column from the right. When a column would go below zero, borrow 1 from the next column to the left, which adds 2 to the current column. If the second number is larger, subtract in the other order and put a minus sign on the answer. 1000 − 11 = 101 (8 − 3 = 5).
- What is the difference between a logical and an arithmetic right shift?
- A logical right shift fills the vacated top bits with zeros, so it treats the pattern as an unsigned number. An arithmetic right shift copies the original top bit, so a negative two's-complement number stays negative. Both halve the value, but only the arithmetic shift rounds negative values correctly.
- What do AND, OR and XOR do?
- They compare two bit patterns column by column. AND gives 1 only where both bits are 1, OR gives 1 where at least one is 1, and XOR gives 1 where exactly one is 1. AND is used to mask out bits, OR to set bits, and XOR to flip them or to compare for differences.
- Can this calculator handle negative binary numbers?
- In arithmetic mode, yes: put a minus sign in front and the sign rules are applied to the exact result. Bitwise mode takes plain bit patterns instead, because a negative number's pattern depends on the width. Use the Two's Complement Calculator to find the pattern for a negative value.
- How large a binary number can I enter?
- There is no fixed limit, because the arithmetic uses arbitrary-precision integers. Column working is drawn for operands up to 64 bits; beyond that you still get the exact result without the step table. Bitwise operations are limited to the chosen width, up to 128 bits.