DigitHelm

Binary Arithmetic Calculator

Add, subtract, multiply, and divide binary numbers with long-form carry/borrow visualization, column-by-column step table, multi-base output, and overflow detection.

Operation

+
Bit width check:

Quick Examples

What Is the Binary Arithmetic Calculator?

This calculator performs all four binary arithmetic operations, addition, subtraction, multiplication, and division, with full visual step-by-step working. It is designed for computer science students, digital electronics learners, and developers who need to understand or verify binary arithmetic at the bit level.

  • Long-form addition display, shows each column's carry bit above the digits, just like long addition in decimal, so you can follow exactly how carry propagates.
  • Column-by-column step table, for addition, every bit column is listed with its A bit, B bit, carry-in, raw sum, result bit, and carry-out.
  • Multi-base output, results shown in binary, decimal, hexadecimal, and octal simultaneously.
  • Bit-width overflow detection, select 4, 8, 16, or 32-bit mode and the calculator flags results that overflow the chosen width.
  • Partial products for multiplication, the long multiplication layout shows each shifted partial product before they are summed, mirroring how hardware multipliers work.

Formula

Binary Addition Rules (per bit column)

0 + 0 = 0  (sum = 0, carry = 0)

0 + 1 = 1  (sum = 1, carry = 0)

1 + 0 = 1  (sum = 1, carry = 0)

1 + 1 = 10₂  (sum = 0, carry = 1)

1 + 1 + 1 = 11₂ (sum = 1, carry = 1) ← with carry-in

Full Adder Equations

Sum = A ⊕ B ⊕ Cin

Cout = (A · B) + (Cin · (A ⊕ B))

Binary Subtraction (borrow method)

0 − 0 = 0   1 − 0 = 1   1 − 1 = 0

0 − 1: borrow from next column → 10₂ − 1 = 1, borrow = 1

Two's Complement (for negative / subtraction)

−B = ~B + 1 (invert all bits, add 1)

A − B = A + (−B) = A + ~B + 1

Full Adder Truth Table

ABCinSumCout
00000
01010
10010
11001
00110
01101
10101
11111

Cin = carry input from the previous (less-significant) column. Cout = carry output to the next (more-significant) column. Sum = the result bit for this column. ⊕ = XOR.

Binary Multiplication Rules

0 × 0 = 0   0 × 1 = 0   1 × 0 = 0   1 × 1 = 1

Multiply A by each bit of B; shift partial products left by bit position.

Sum all partial products using binary addition.

How to Use

  1. 1
    Select an operation: Click Addition (+), Subtraction (−), Multiplication (×), or Division (÷) at the top.
  2. 2
    Enter two binary numbers: Type in fields A and B using only 0s and 1s, invalid characters are automatically removed. The decimal equivalent appears beside each field as you type.
  3. 3
    Choose a bit width (optional): Select 4, 8, 16, or 32-bit mode to check for overflow. Leave on Auto to work with any size.
  4. 4
    Use a quick example: Click any preset button, e.g. "overflow" or "5 × 3", to instantly fill a worked example.
  5. 5
    Press Enter or click Calculate: The long-form visual display appears with the carry/borrow row, aligned operands, and result. Multi-base output shows the answer in binary, decimal, hex, and octal.
  6. 6
    Expand the step table: For addition, click "Show column-by-column step table" to see every bit position tabulated with carry-in, sum, and carry-out, ideal for homework and exam prep.

Example Calculation

Adding 1011₂ (11) + 0110₂ (6) with carry tracking

Carry row (above each column):

Carry: ·  1  1  1  ·

A: 1 0 1 1

+ B: 0 1 1 0

─────────────

Result: 1 0 0 0 1

ColBit ABit BCinSumResult BitCout
1100110
2110201
3011201
4101201
1110

Key observation, carry propagation

Notice how the carry generated at column 2 (1+1 = 10) propagates through columns 3 and 4, each generating another carry, until it finally escapes as the overflow bit on the far left. This is called a carry ripple, the worst case for adder speed in hardware.

Multiplication example: 0101₂ (5) × 0011₂ (3)

0101 (A = 5)

× 0011 (B = 3)

──────

0101 (0101 × 1, shift 0)

01010 (0101 × 1, shift 1)

000000 (0101 × 0, shift 2)

000000 (0101 × 0, shift 3)

──────────

001111 = 15 ✓

Understanding Binary Arithmetic

Why Binary Arithmetic Is the Foundation of Computing

Every smartphone, laptop, and server processor performs billions of arithmetic operations per second, and every single one of them, at the transistor level, is binary arithmetic. The number 42 stored in a computer is actually the pattern 00101010 in eight bits. Adding two numbers means adding those patterns using the four simple rules of binary addition.

Understanding binary arithmetic is not just academic. It is essential for writing efficient code, debugging bitwise operations, understanding integer overflow bugs, designing embedded systems, and making sense of signed integer representations like two's complement.

From Half Adder to Ripple-Carry Adder

The simplest binary addition circuit is the half adder, two logic gates (XOR and AND) that add two single bits and output a sum bit and a carry bit. But a half adder cannot handle a carry coming in from a less-significant column.

A full adder solves this by accepting three inputs: bit A, bit B, and carry-in (Cin). It produces a sum bit (A ⊕ B ⊕ Cin) and a carry-out (Cout). Chain 8 full adders together and you have an 8-bit ripple-carry adder, the same structure illustrated by this calculator's column-by-column display.

The worst-case carry ripple

Try adding 01111111 (127) + 00000001 (1) = 10000000 (128). Every column produces a carry that forces the next column to wait, the carry literally "ripples" from bit 0 to bit 7. In a real CPU this takes 8 gate delays for an 8-bit adder, or 64 for a 64-bit adder. This is why modern processors use carry-lookahead adders that compute carries in parallel, completing a 64-bit addition in just a few gate delays regardless of the inputs.

Binary Subtraction and Two's Complement

There are two ways to subtract in binary. The borrow method mirrors decimal long subtraction: when a column cannot subtract (0 − 1), you borrow 2 from the next column, leaving a debt (borrow) that reduces the next column's minuend.

The method used by every modern CPU is different: two's complement. To compute A − B, the processor negates B (flip all bits and add 1) then adds the result to A. This means the hardware only needs one adder circuit, subtraction is free, because negation is cheap.

  • To negate a binary number: invert every bit (ones' complement), then add 1.
  • Example: negate 0110 (6) → invert → 1001 → add 1 → 1010 (−6 in 4-bit two's complement)
  • Then: 1011 (11) + 1010 (−6) = 1 0101, drop the overflow carry → 0101 (5). ✓

Binary Multiplication: Partial Products

Binary multiplication follows the same logic as decimal long multiplication but is much simpler: multiplying by a single bit can only result in 0 (if the bit is 0) or the multiplicand itself (if the bit is 1). This makes the partial products trivial to generate, no multiplication tables to memorize.

Each bit of the multiplier B generates one partial product: the multiplicand A shifted left by the bit position. Partial products with a 1 bit are included; those with a 0 bit are zero. The final result is the binary sum of all partial products.

Overflow and Bit Width

In a real computer, integers are stored in a fixed number of bits, 8, 16, 32, or 64. If the result of an addition exceeds that bit width, the extra bit is lost and the stored result wraps around. This is integer overflow, a real-world bug that has caused infamous disasters including the Ariane 5 rocket explosion (1996) where a 64-bit to 16-bit conversion overflowed mid-flight.

  • In 4-bit unsigned arithmetic: 1111 (15) + 0001 (1) = 10000, but only 0000 (0) is stored, the carry escapes.
  • The calculator detects overflow in 4/8/16/32-bit modes and shows exactly how many bits the result overflows by.
  • Two's complement signed overflow is a different check: when the sign bit of the result is wrong relative to the inputs.

Hexadecimal and Its Relationship to Binary

Hexadecimal (base 16) is the most common shorthand for binary. Every 4 binary bits correspond to exactly one hex digit (0–9, A–F). This makes conversion between binary and hex instantaneous: split the binary string into groups of 4 from the right and look up each group.

1010 0111 1100 1101

 ↓   ↓   ↓   ↓

 A   7   C   D → 0xA7CD

This is why memory addresses and color codes (#FF8800) are written in hex, they represent binary values in a form that humans can read and compare without counting 16+ zeros.

Frequently Asked Questions

How does binary addition work?

Binary addition works exactly like decimal long addition, process columns right to left, carry when the sum is too big for one digit.

The four rules are:

  • 0 + 0 = 0 (sum = 0, no carry)
  • 0 + 1 = 1 (sum = 1, no carry)
  • 1 + 0 = 1 (sum = 1, no carry)
  • 1 + 1 = 10₂, write 0 in the column, carry 1 to the left

When there is also a carry-in from the previous column: 1 + 1 + 1 = 11₂, write 1, carry 1.

The calculator shows these carries in a row above the operands, just like pencil-and-paper binary addition.

What is the difference between a half adder and a full adder?

Half adder: adds two bits. Inputs: A, B. Outputs: Sum (A ⊕ B), Carry (A · B). Only works for the rightmost bit position, it has no carry-in input.

Full adder: adds three bits. Inputs: A, B, Cin. Outputs: Sum (A ⊕ B ⊕ Cin), Cout ((A·B) + (Cin·(A⊕B))). Used for every column except the first.

A multi-bit adder chains full adders together:

  • The rightmost column uses a half adder (or full adder with Cin = 0)
  • Each subsequent column is a full adder that receives the Cout of the previous column as its Cin
  • The final Cout is either discarded (unsigned) or signals overflow

This structure is called a ripple-carry adder, visible in the carry row of this calculator's addition display.

What is two's complement and why do computers use it?

Two's complement is the universal standard for signed integers in computers. To negate a binary number:

  • Start with the binary representation of the positive value
  • Flip every bit (0→1, 1→0), this gives the ones' complement
  • Add 1 to the ones' complement → this is the two's complement (= the negative value)

Example: negate 0110₂ (6 in 4-bit)

  • 0110 → flip → 1001 (ones' complement)
  • 1001 + 1 = 1010 (two's complement of 6 = −6 in 4-bit signed)

Why computers use it:

  • Subtraction is just addition of the negated value, one circuit handles both operations
  • Only one representation of zero (unlike sign-magnitude or ones' complement)
  • Arithmetic wraps around naturally at the boundaries

What is binary overflow and how does it happen?

Overflow happens when the arithmetic result exceeds the storage capacity of the bit width being used.

  • 4-bit unsigned: can represent 0–15. Adding 15 + 1 = 16, which needs 5 bits → overflow
  • 8-bit unsigned: can represent 0–255. Adding 200 + 100 = 300 → overflow
  • 8-bit signed (two's complement): range −128 to +127. Adding 100 + 100 = 200 → overflow into negative territory

In real programs, overflow can cause:

  • Silent wrap-around (C/C++ unsigned integers wrap; signed overflow is undefined behaviour)
  • Security vulnerabilities (buffer size calculations that overflow to 0 or small values)
  • Incorrect loop conditions or array index calculations

Use the bit-width selector in this calculator to see exactly which results overflow for your target platform.

How does binary multiplication work?

Binary multiplication mirrors decimal long multiplication but is simpler, a binary bit is either 0 or 1, so each partial product is either A shifted left, or 0.

Steps for A × B:

  • Write B vertically from least-significant (right) to most-significant (left) bit
  • For each bit of B: if bit = 1, write A shifted left by that bit's position; if bit = 0, write all zeros
  • Add all partial products using binary addition

Result size: an n-bit × m-bit multiplication can produce up to (n + m) bits of result. This is why CPU multipliers are wider than the ALU, a 32×32 bit multiply can produce a 64-bit result.

Why is hex (hexadecimal) commonly used alongside binary?

Hexadecimal is the natural shorthand for binary because 4 bits map perfectly to one hex digit (since 2⁴ = 16 = the hex base):

  • 0000 = 0x0, 0001 = 0x1, … 1001 = 0x9
  • 1010 = 0xA, 1011 = 0xB, 1100 = 0xC, 1101 = 0xD, 1110 = 0xE, 1111 = 0xF

Practical uses:

  • Memory addresses: 0xFFFF800000000000 is clearer than 64 binary digits
  • Web colors: #FF8800 is easier to read than 11111111 10001000 00000000
  • CPU registers and machine code: debuggers display values in hex
  • Bit masks: 0x0F = 00001111, visually obvious which bits are set

Can binary numbers have a fractional part?

Binary numbers can represent fractions using positions after the binary point, each worth a negative power of 2:

  • 0.1₂ = 1/2 = 0.5
  • 0.01₂ = 1/4 = 0.25
  • 0.001₂ = 1/8 = 0.125
  • 0.11₂ = 1/2 + 1/4 = 0.75

The problem: many decimal fractions have no finite binary representation. 0.1 in decimal requires an infinitely repeating pattern in binary (0.0001100110011…₂), truncated by the hardware. This is why:

  • 0.1 + 0.2 ≠ 0.3 in most programming languages (floating-point rounding)
  • IEEE 754 defines exactly how this truncation is handled in 32-bit and 64-bit floats
  • Financial software uses decimal arithmetic (not binary floats) to avoid rounding errors

This calculator handles integer binary numbers. For binary fractions and IEEE 754 representation, see the Floating Point Converter.

Does the calculator save my inputs?

Yes, all inputs are automatically saved to your browser's localStorage as you type:

  • Binary inputs A and B are remembered across sessions
  • The selected operation (add/subtract/multiply/divide) is saved
  • The bit-width selection (4/8/16/32-bit) is preserved
  • Nothing is sent to any server, all data stays in your browser

Click Reset to clear the form and delete the saved data, returning everything to default values.

Related Calculators