UNIHIVE

Study Hub UNIPORT IFT 211

IFT 211 · Digital Logic Design

Binary arithmetic

Adding, subtracting, multiplying and dividing in binary, and what overflow means.

Our notes

1 min read

Addition rules

0 + 0 = 0; 0 + 1 = 1; 1 + 1 = 10 (write 0, carry 1); 1 + 1 + 1 = 11 (write 1, carry 1).

Worked example: addition

  0101 1011 (91)
+ 0011 0110 (54)
= 1001 0001 (145)
Work from the right: 1 + 0 = 1; 1 + 1 = 0 carry 1; 0 + 1 + 1 = 0 carry 1; 1 + 0 + 1 = 0 carry 1; 1 + 1 + 1 = 1 carry 1; 0 + 1 + 1 = 0 carry 1; 1 + 0 + 1 = 0 carry 1; 0 + 0 + 1 = 1. Check: 91 + 54 = 145 = 128 + 16 + 1.

Subtraction

Rules: 0 − 0 = 0; 1 − 0 = 1; 1 − 1 = 0; 0 − 1 = 1 with a borrow from the next column. In practice computers subtract by adding the two's complement (next topic), so the same adder does both jobs.

Worked example: subtraction by borrowing

1100 (12) − 0101 (5), working from the right:

  • Column 1: 0 − 1 needs a borrow. Column 2 is 0, so the borrow comes from column 3 (which becomes 0); column 2 becomes 10₂, lends 1 and keeps 1; column 1 becomes 10₂ − 1 = 1.
  • Column 2: 1 − 0 = 1.
  • Column 3: 0 − 1 needs a borrow from column 4 (which becomes 0): 10₂ − 1 = 1.
  • Column 4: 0 − 0 = 0.
  • Result 0111 = 7. Check: 12 − 5 = 7.

Multiplication

Like long multiplication in decimal, but each partial product is either 0 or a shifted copy of the multiplicand.

  • 1011 (11) × 101 (5): 1011 + 0000 shifted one place + 1011 shifted two places = 1011 + 101100 = 110111 (55).
  • Multiplying by 2 is a shift left by one place; dividing by 2 is a shift right.

Division

Long division with subtract-and-shift: 1101 (13) ÷ 11 (3) gives quotient 100 (4) and remainder 1.

Overflow and carry

With a fixed number of bits, a result can be too big.

  • Unsigned: a carry out of the top bit means overflow. 1111 0000 (240) + 0010 0000 (32) = 1 0001 0000: in 8 bits the result shows 16, wrong, because 272 needs 9 bits.
  • Signed: overflow happens when two numbers of the same sign give a result of the other sign (next topic).

BCD arithmetic

In BCD each decimal digit has 4 bits. If a digit's sum is over 9 (or makes a carry), add 6 (0110) to correct it. 8 + 5 = 1101 → +0110 = 1 0011, read as BCD 13.

Exams usually ask

  • Add, subtract, multiply and divide binary numbers showing carries.
  • Explain overflow; do a BCD addition with the +6 correction.

Common mistake

Forgetting the carry that comes from 1 + 1 + 1, which writes 1 and carries 1.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

Practise

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All IFT 211 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.