Skip to content
LearnTronics menu

LearnTronics

Math

Math Index

Binary Arithmetic

We already know how to read binary numbers. Now we can do arithmetic with them. The familiar ideas are the same as in decimal arithmetic: addition, carrying, subtraction, borrowing, and multiplication. The difference is that every digit can only be 0 or 1.

Do not confuse binary arithmetic with Boolean algebra. In ordinary base-2 arithmetic, 1 + 1 = 10. In Boolean algebra, where + commonly means OR, 1 + 1 = 1.

Binary addition

ABSum bitCarryWritten result
00000
01101
10101
110110
The important new rule is:
1 + 1 = 10
Write 0 in the current column and carry 1 into the next column.

Worked example 1 — 5 + 3

101 + 011 ----- 1000
1. Right column: 1 + 1 = 10. Write 0 and carry 1.
2. Middle column: 0 + 1 + carry 1 = 10. Write 0 and carry 1.
3. Left column: 1 + 0 + carry 1 = 10. Write 0 and carry 1.
4. The final carry becomes a new leftmost 1.
101₂ + 011₂ = 1000₂ 5 + 3 = 8

Worked example 2 — 11 + 6

1011 + 0110 ------ 10001

Checking in decimal: 11 + 6 = 17, and 10001₂ is 17.

A carry input makes three bits

Once a carry is present, a column may contain three 1s:

1 + 1 + 1 = 11₂

Write 1 in the current column and carry 1 into the next.

ABCarry inSumCarry out
00000
00110
01010
01101
10010
10101
11001
11111

This is also the behavior of a digital full adder: a circuit that adds two data bits plus a carry from the previous column.

Binary subtraction

OperationResult
0 − 00
1 − 01
1 − 10
0 − 1Borrow from the next column
When we borrow 1 from the next binary column, it is worth 10₂ in the current column — decimal 2.

Worked example 3 — 7 − 3

111 -011 ---- 100
111₂ − 011₂ = 100₂ 7 − 3 = 4

Worked example 4 — borrowing through zeros: 8 − 1

1000 -0001 ----- 0111

The rightmost 0 cannot subtract 1, so the borrow travels left through the zeros until it reaches the 1 in the 8s position.

1000₂ − 0001₂ = 0111₂ 8 − 1 = 7

Binary multiplication

Binary multiplication is simple because each multiplier digit is either 0 or 1.

ABA × B
000
010
100
111

Worked example 5 — 5 × 3

101 × 11 ----- 101 + 1010 ------ 1111
101₂ × 11₂ = 1111₂ 5 × 3 = 15

Shifting left and right

OperationExampleUnsigned whole-number effect
Left one place0011 → 0110Multiply by 2
Left two places0011 → 1100Multiply by 4
Right one place1100 → 0110Divide by 2

Fixed width and overflow

A 4-bit unsigned register can represent:

0000₂ through 1111₂

That is decimal 0 through 15.

Worked example 6 — 4-bit overflow

1111 +0001 ----- 10000

The mathematical answer needs five bits. If the storage location has only four, the extra leftmost bit is a carry out.

The maximum unsigned value that can be stored in n bits is:
2ⁿ − 1
For 8 bits: 2⁸ − 1 = 255.

Try these yourself

Problem 1

101₂ + 10₂
Show answer
111₂

5 + 2 = 7.

Problem 2

111₂ + 1₂
Show answer
1000₂

7 + 1 = 8.

Problem 3

1010₂ + 0111₂
Show answer
10001₂

10 + 7 = 17.

Problem 4

1101₂ − 0101₂
Show answer
1000₂

13 − 5 = 8.

Problem 5

10000₂ − 1₂
Show answer
1111₂

16 − 1 = 15.

Problem 6

110₂ × 11₂
Show answer
10010₂

6 × 3 = 18.

Where we go next

So far these are unsigned binary numbers. A later lesson can introduce signed binary and two's complement, which allows negative values and makes subtraction especially convenient in digital hardware.