$ man binary-calculator
Binary Calculator
NAME
binary-calculator — Add, subtract, multiply, divide, shift, AND, OR and XOR binary numbers of any length. Shows the carry and borrow columns plus decimal, hex and octal.
SYNOPSIS
# What is a binary calculator?
A binary calculator performs arithmetic and bitwise logic directly on base-2 numbers, adding, subtracting, multiplying, dividing, shifting and combining them with AND, OR and XOR, and showing the answer in binary, decimal, hex and octal.
WHY HERE
Number-base and data utilities for developers working with APIs.
Carry 11110
1011
+ 1101
-----
11000| Base | Result |
|---|---|
| Binary (base 2) | 11000 |
| Decimal (base 10) | 24 |
| Hexadecimal (base 16) | 18 |
| Octal (base 8) | 30 |
- 1011 is 11 in decimal and 1101 is 13.
- Add column by column from the right. 1 + 1 is 0 carry 1, and 1 + 1 + 1 is 1 carry 1 — there is no digit 2 to write.
- 11 + 13 = 24, which is 11000 in binary.
USAGE
01 → Type two binary numbers
Only the digits 0 and 1. Spaces and underscores between nibbles are ignored, so 1011_0110 is fine, but a stray 2 or an 8 is rejected rather than quietly truncated at it.
02 → Pick the operation
Arithmetic (+ − × ÷) treats the inputs as numbers. AND, OR and XOR treat them as bit patterns, so they line the bits up from the right and the answer has nothing to do with place value.
03 → Enter a shift in decimal
For a shift, the second box is a count of bit positions, so type 3 and not 11. Shifting left by n multiplies by 2ⁿ; shifting right by n divides by 2ⁿ and discards the bits that fall off the end rather than rounding.
04 → Read the carry row
Addition and subtraction show the carry or borrow column by column from the right, which is the part a course wants to see. 1 + 1 is 0 carry 1 — there is no digit 2 to write down.
DESCRIPTION
Binary arithmetic follows exactly the rules of decimal arithmetic with ten replaced by two, which means the only genuinely new habit is carrying earlier. 1 + 1 fills the column and carries into the next, so 1011 + 1101 is 11000: twenty-four, which is 11 + 13. Subtraction borrows the same way, except that a borrowed 1 from the next column up is worth two rather than ten. Multiplication is easier in binary than in decimal because the times table only has the entries 0 and 1 — long multiplication becomes nothing more than adding shifted copies of the first number, one for each 1 bit in the second.
Division is the operation where a binary calculator and a pocket calculator disagree, and the disagreement is the point. 100101 ÷ 101 is 111 remainder 10 — thirty-seven divided by five is seven remainder two. That integer quotient is what a long-division exercise and a CPU's integer divide instruction both produce. The exact value 7.4 also exists, and in binary it is 111.0110011001100…, a repeating expansion, so this tool shows the quotient and remainder first and the binary fraction second, marked where it had to be cut off.
AND, OR and XOR are not arithmetic at all. They line the two numbers up bit by bit and combine each pair independently, with no carry anywhere, so place value plays no part: 1100 AND 1010 is 1000, 1100 OR 1010 is 1110, and 1100 XOR 1010 is 0110. AND is how you mask bits off, OR is how you set them on, and XOR flips them — and because XOR applied twice returns the original, it is the basis of the simplest reversible ciphers and of swapping two values without a temporary.
All the arithmetic here is done in arbitrary-precision integers, so a sixty-four-bit operand is not special and nothing silently overflows. That also means negative results are shown as a minus sign in front of the magnitude rather than wrapped into a two's-complement pattern, because a two's-complement answer only means something once you have fixed a word width. For the same reason AND, OR, XOR and shifts here require non-negative operands: the bit pattern of a negative number does not exist until you choose 8, 16, 32 or 64 bits.
FAQ
## How do you add binary numbers?
Column by column from the right, carrying whenever a column reaches two. 0+0=0, 0+1=1, and 1+1=0 carry 1. With a carry already coming in, 1+1+1=1 carry 1. So 1011 + 1101 = 11000, which checks out as 11 + 13 = 24.
## What is 101 divided by 10 in binary?
10 remainder 1, that is 5 ÷ 2 = 2 remainder 1. As a binary fraction it is 10.1, since .1 in binary is one half. This calculator gives you both the quotient-and-remainder form and the fraction.
## Why does the calculator refuse a negative number for AND or XOR?
Because a bit pattern for a negative number only exists once you have chosen a word width: −3 is 11111101 in eight bits and 1111111111111101 in sixteen, and AND against those two gives different answers. Rather than pick a width for you, the tool asks for non-negative operands.
## Is shifting right the same as dividing by two?
For non-negative numbers it is division by two rounded down, which is the same thing only when the number is even. 1011 >> 1 is 101, i.e. 11 >> 1 = 5, not 5.5 — the shifted-out bit is discarded, not rounded.
## How big a number can it handle?
Up to 2,000 digits per operand. The arithmetic uses arbitrary-precision integers rather than 64-bit machine words, so results above 2⁵³ are still exact where an ordinary floating-point calculator would start rounding.