Binary Calculator
Calculate with binary numbers: addition, subtraction, multiplication, division with remainder, bitwise AND, OR, XOR, NOT, and left/right bit shifts. Enter two binary values and get exact results in binary, decimal, hexadecimal and octal, with step-by-step working.
Add, Subtract, Multiply and Combine Binary Numbers
Binary Arithmetic – Basic Rules
Where:
- \(b_i\) — a single bit, either 0 or 1
- \(i\) — the bit position, counted from the right starting at 0
- \(2^i\) — the place value (weight) of that position
Binary numbers use only the digits 0 and 1, and each position is worth a power of 2. Arithmetic works exactly like decimal arithmetic, only with base-2 column tables: for addition \(0+0=0\), \(0+1=1\), and \(1+1=10_2\) (write 0, carry 1); for subtraction \(1-0=1\), \(1-1=0\), and \(0-1\) borrows 1 from the next column (worth 2) to write 1.
For the bitwise operations, each result bit depends only on the two operand bits in the same column, as if the numbers were written one under the other. A left shift by \(k\) places multiplies by \(2^k\) inside a fixed-width word, and an arithmetic right shift by \(k\) divides by \(2^k\), rounding toward \(-\infty\).
Binary Calculator – Calculation Example
Example: add the binary numbers A = 1011 and B = 0110 (the calculator's default values).
First, read both numbers in decimal using the place values \(2^3, 2^2, 2^1, 2^0\):
\[ 1011_2 = 8 + 0 + 2 + 1 = 11_{10}, \qquad 0110_2 = 0 + 4 + 2 + 0 = 6_{10} \]
Now add column by column from the right, carrying a 1 whenever a column sums to 2 or more:
\[ 1011_2 + 0110_2 = 10001_2 \]
Check in decimal: \(11 + 6 = 17\), and indeed \(10001_2 = 16 + 1 = 17\).
Result: 10001 in binary, 17 in decimal, 0x11 in hexadecimal, and 0o21 in octal.
How to use the calculator
- Choose an Operation from the dropdown: Addition, Subtraction, Multiplication, Division with remainder, one of the bitwise operators (AND, OR, XOR, NOT), or a bit shift (A << B, A >> B).
- Enter the First number (A) using only the digits 0 and 1, with an optional leading minus for negative values. Spaces inside the number are ignored.
- Enter the Second number (B) the same way. For NOT only A is used; for the shifts, B is the shift amount (also written in binary).
- For NOT, left shift and right shift, choose a Bit width (8, 16, 32 or 64 bits). The result of these three operations is a two's-complement word of that width.
- Read the Results: the answer in binary, plus its decimal, hexadecimal and octal equivalents. Division also shows the remainder, and the Calculation steps panel explains how the answer was built.
What binary arithmetic means
Binary is the number system of digital hardware: a bit is 0 or 1 because a transistor is off or on. Every binary number is a sequence of bits in which position \(i\) from the right carries the weight \(2^i\). So 1011 is not "one thousand and eleven" but \(1\cdot8 + 0\cdot4 + 1\cdot2 + 1\cdot1 = 11\). Once you read numbers this way, all four basic operations follow the familiar school method — you simply carry at 2 instead of at 10.
The bitwise operations work differently: they treat each column independently, which makes them ideal for masks and flags. The AND of two numbers keeps only the bits set in both; OR keeps the bits set in at least one; XOR keeps the bits set in exactly one. The table below shows the rule for a single column:
| A | B | A AND B | A OR B | A XOR B |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Shifts are the binary shortcut for scaling by powers of two. Shifting 1011 left by 2 gives 101100, which is \(11 \times 4 = 44\) — provided no bits fall off the left edge of the word. This is why the bit width matters: inside a 32-bit register, 1 shifted left by 31 is still fine, but shifted left by 32 the bit disappears and the result wraps to 0. Computer scientists use this everywhere from image masks to IP subnetting, where a CIDR calculator applies the same bitmask logic to address ranges.
To convert a single number between bases rather than calculate with two of them, use the Binary Converter; the Hex Converter does the same for the hexadecimal notation programmers often prefer.
Assumptions, limitations and tips
- Up to 1024 bits per input. All arithmetic uses exact integer math, so even very long binaries give an exact answer — no rounding, no overflow for the add, subtract, multiply, divide and bitwise modes.
- NOT and shifts are fixed-width. They are evaluated inside the word size you pick, exactly as a CPU register would. The hexadecimal and octal results of these operations are shown as unsigned bit patterns of that width, padded with leading zeros.
- Division truncates toward zero and reports the remainder, matching the behavior of
/and%in JavaScript, C and Java: A = B × Q + R with |R| < |B|, and R takes the sign of A. - Step tables (carry rows, borrow rows, bitwise columns) are drawn for inputs of up to 64 bits and, for multiplication, up to 24 set bits in B; longer inputs are still computed exactly, just without the illustrated breakdown.
- Leading zeros change nothing numerically —
0110and110are both 6 — but NOT and shifts use them to define the word shape, so enter the width explicitly if the padding matters to you. - Negative numbers are accepted only in signed-magnitude form (a leading minus); the calculator converts them internally and shows the result with a minus sign, not as a two's-complement pattern (except in NOT and shift mode).
Frequently Asked Questions
How do I convert a binary number to decimal by hand?
Write the powers of 2 above each bit, from right to left: 1, 2, 4, 8, 16, and so on, then add up the powers that sit under a 1. For example, \(1101_2 = 8 + 4 + 0 + 1 = 13\). The rightmost bit (position 0) always has weight \(2^0 = 1\), and each step left doubles the weight.
How do I convert a decimal number to binary step by step?
Divide the number by 2 repeatedly, writing down the remainder at each step, until you reach 0. Then read the remainders from bottom to top. For 13: \(13 \div 2 = 6\) rem 1, \(6 \div 2 = 3\) rem 0, \(3 \div 2 = 1\) rem 1, \(1 \div 2 = 0\) rem 1 — the remainder sequence 1101 is the binary form.
Why does 1 + 1 equal 10 in binary?
Because there is no digit 2 in binary. When a column sums to 2, you write 0 in that column and carry 1 into the next column on the left, exactly like carrying when a decimal column exceeds 9. So \(1 + 1 = 10_2\), which reads as "one zero" — the binary way of writing two (one group of two, plus zero ones).
What's the difference between AND, OR and XOR?
All three compare the two numbers column by column. AND gives 1 only where both operands have a 1 — useful for extracting or masking bits. OR gives 1 where at least one operand has a 1 — useful for setting bits. XOR gives 1 where exactly one operand has a 1 — useful for toggling bits, and XOR of a number with itself is always 0.
Why do I need to choose a bit width for NOT and shifts?
NOT and shifts change the number of bits in the result, so the answer depends on the container size, just as it does in a CPU register. Inside an 8-bit word, NOT 0000 0101 flips every bit including the leading zeros, giving 1111 1010. Similarly, a left shift by k places multiplies by \(2^k\) only if no bits fall off the left edge of the word — otherwise the value wraps.
What happens with negative numbers in binary?
This calculator accepts negative inputs written with a leading minus and computes exact signed results. For the fixed-width NOT and shift operations, however, negative numbers follow the two's complement convention, where \(-A\) is stored as \(2^w - A\) in a w-bit word, and NOT A equals \(-A - 1\). That is why NOT 0 in any width gives a result of −1.
What are the most common mistakes when doing binary arithmetic by hand?
Forgetting the carry when a column sums to 2, borrowing 10 instead of 2 during subtraction, and misreading the result as decimal digits (1011 is eleven, not one thousand eleven). Also watch the shift direction: shifting left multiplies by \(2^k\) while shifting right divides by it, discarding the remainder — a right shift of 1011 (11) by 1 gives 101 (5), not 22.
Does binary division produce a fractional result?
No — this calculator performs integer division with a remainder, like the / and % operators in JavaScript, C or Java. The quotient truncates toward zero, and the remainder satisfies A = B × Q + R with the remainder taking the sign of the dividend. Division by zero is rejected and shows an error, since it has no defined quotient.