Binary arithmetic calculator
Run arithmetic and bitwise operations on two binary numbers: add, subtract, multiply, divide (integer quotient), plus the bitwise AND, OR and XOR. Every result is shown at once in binary, decimal and hexadecimal — useful for learning binary maths or debugging bit flags.
How it works
Each operand is validated to contain only 0 and 1, then parsed into an
arbitrary-precision integer (BigInt) by accumulating value × 2 + bit. The
selected operation is applied directly to those integers — +, −, ×, integer
÷, or the bitwise &, |, ^. The result is then formatted back into binary,
decimal and hex. Because BigInt is used, even long strings compute exactly with no
overflow.
Example
With A = 1010 (10) and B = 0110 (6):
| Operation | Binary | Decimal | Hex |
|---|---|---|---|
| Add | 10000 | 16 | 0x10 |
| Subtract | 100 | 4 | 0x4 |
| Multiply | 111100 | 60 | 0x3C |
| Divide | 1 | 1 | 0x1 |
| AND | 10 | 2 | 0x2 |
| OR | 1110 | 14 | 0xE |
| XOR | 1100 | 12 | 0xC |
Everything runs locally in your browser — nothing is uploaded.
Understanding binary arithmetic step by step
Addition and the carry bit
Binary addition follows the same rules as decimal addition, but with only two
digits. When two 1 bits are added the result is 10 in binary (decimal 2), so the
1 carries into the next column — exactly like carrying a 10 into the next
column in decimal arithmetic. For example:
1010 (10)
+ 0110 ( 6)
------
10000 (16)
Reading right to left: 0+0=0, 1+1=10 (write 0 carry 1), 0+1+1=10 (write 0 carry 1), 1+0+1=10 (write 0 carry 1), then the final carry gives the leading 1.
Subtraction: borrowing in base 2
Subtraction borrows from the next column just like decimal, but the borrowed amount is 2 (since the base is 2). When you borrow, the column you borrowed from decrements by 1. This can cascade through multiple columns of zeros.
Multiplication by repeated shifting
Binary multiplication uses the same long-multiplication pattern as decimal: multiply by each digit and shift left one position per digit. Multiplying by a binary digit is trivial — it is either the number (×1) or zero (×0) — so binary multiplication reduces to a series of conditional shifts and additions.
Bitwise vs arithmetic: a key distinction
The three bitwise operations work column by column with no carry between columns. Each output bit depends only on the two input bits in the same position:
| A bit | B bit | AND | OR | XOR |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Practical uses in programming: AND with a mask extracts specific bits (flags & 0b1111
keeps only the lowest four); OR sets specific bits; XOR toggles bits or checks
whether two values differ in a specific position.
When this calculator is useful
- Computer architecture coursework — verifying hand-calculated binary addition and multiplication answers
- Embedded and systems programming — checking bit masks and flag operations before writing C or assembly code
- Interview preparation — binary arithmetic questions appear frequently in software engineering interviews, and seeing the decimal and hex alongside the binary result builds intuition
- Base conversion — the simultaneous binary, decimal, and hex output makes it easy to check that a binary string means what you think it means