Add two positive 8-bit binary integers

Data Representation – Adding Two Positive 8‑bit Binary Integers

Learning Objectives (AO1 & AO2)

  • Convert accurately between decimal, binary and hexadecimal (8‑bit) representations.
  • Perform binary addition of two positive 8‑bit numbers and decide whether the result fits in a byte.
  • Identify and explain unsigned overflow and signed (two’s‑complement) overflow.
  • Apply logical left‑ and right‑shifts as a quick way to multiply or divide by powers of two.
  • Add a positive and a negative two’s‑complement number and interpret the result.

Key Concepts Overview

  • Binary numeral system – base 2, digits 0 and 1.
  • 8‑bit unsigned range – 0 to \(2^{8}-1 = 255\).
  • 8‑bit signed (two’s‑complement) range – –128 to +127.
  • Overflow terminology (as used in the Cambridge syllabus):
    • Unsigned overflow: a carry out of the most‑significant bit (MSB).
    • Signed overflow: the carry into the MSB differs from the carry out of the MSB (equivalently, adding two numbers with the same sign produces a result with a different sign).
  • Binary addition rules (including the case of three bits being added):
Bits addedSum bitCarry‑out
0 + 000
0 + 110
1 + 010
1 + 101
1 + 1 + 111

Number‑System Conversions

Decimal → 8‑bit Binary

  1. Divide the decimal number by 2, record the remainder.
  2. Repeat with the quotient until it becomes 0.
  3. Read the remainders in reverse order; pad with leading 0’s to obtain exactly 8 bits.

Binary → Hexadecimal (8‑bit)

  1. Group the binary number into two 4‑bit nibbles (from the right).
  2. Convert each nibble to its hexadecimal digit (0‑F).

Hexadecimal → Binary (8‑bit)

  1. Write each hex digit as its 4‑bit binary equivalent.
  2. Combine the two groups to obtain the full 8‑bit binary pattern.
DecimalBinary (8‑bit)Hexadecimal
00000 000000
100000 10100A
450010 11012D
780100 11104E
2551111 1111FF

Two’s‑Complement (Signed) Representation

Logical Shifts

Step‑by‑Step Procedure for Adding Two Positive 8‑bit Numbers

  1. Write each operand as an 8‑bit binary string. Add leading zeros if necessary.
  2. Align the numbers vertically** with the least‑significant bit (LSB) on the right.
  3. Column‑wise addition** starting at the LSB. Record the sum bit and the carry to the next column.
  4. Proceed to the MSB. If a carry remains after the MSB, an unsigned overflow has occurred.
  5. Signed‑overflow check** (two’s‑complement only): compare the carry **into** the MSB with the carry **out of** the MSB. If they differ, a signed overflow has occurred.
  6. Optional verification:** Convert the binary result back to decimal (or hex) to confirm.

Worked Example – Unsigned Addition (No Overflow)

Add 45₁₀ and 78₁₀.

Step 1 – Decimal → 8‑bit Binary

Decimal8‑bit Binary
450010 1101
780100 1110

Step 2 – Column‑wise Binary Addition

Bit position76543210
A00101101
B01001110
Carry‑in00000000
Sum01110111
Carry‑out00000000

Result: 0111 0111₂ → \(64+32+8+4+2+1 = 111_{10}\).

Carry‑out from the MSB = 0 → no unsigned overflow. MSB = 0, so there is also no signed overflow.

Worked Example – Signed Overflow (Two’s‑Complement)

Add +120₁₀ and +100₁₀ as signed 8‑bit numbers.

DecimalBinary (8‑bit)
+1200111 1000
+1000110 0100

Binary addition yields 1101 1100 with a carry‑out of 0.

  • MSB = 1 → the result would be interpreted as negative in two’s‑complement.
  • Carry into the MSB = 1, carry out = 0 → they differ → signed overflow.
  • Interpreting 1101 1100₂ as two’s‑complement gives –36, not the expected +220.

Worked Example – Adding a Positive and a Negative Two’s‑Complement Number

Add +45₁₀ and –20₁₀.

DecimalBinary (8‑bit)
+450010 1101
–201110 1100

Column‑wise addition:

Bit76543210
A00101101
B11101100
Carry‑in00000000
Sum10001001
Carry‑out01101000

Result = 1000 1001₂. Interpreting as two’s‑complement gives –31, which is indeed 45 + (‑20) = 25? Wait – correction: the correct two’s‑complement for –20 is 1110 1100, adding yields 0010 1111₂ = 47. The previous table contained a mistake; the final correct result is:

StepBinary
+450010 1101
–20 (two’s‑complement)1110 1100
Sum0001 1001

Result = 0001 1001₂ = 25₁₀. No overflow occurs (carry out of MSB = 0, carries into/out of MSB are equal).

Overflow Summary Table

TypeConditionInterpretation
Unsigned overflowCarry out of the MSB = 1True sum > 255 (does not fit in an 8‑bit byte)
Signed overflow (two’s‑complement)Carry‑into MSB ≠ Carry‑out MSBResult cannot be represented in the range –128 … +127

Check‑Your‑Understanding Boxes (AO2)

Box 1 – Hexadecimal to Binary
Convert 0x3A to an 8‑bit binary number.
Box 2 – Unsigned Overflow Detection
Add 1101 1010₂ (218) and 0110 1111₂ (111). State whether unsigned overflow occurs and give the 8‑bit result.
Box 3 – Signed Overflow Explanation
Explain why adding 0111 1110₂ (+126) and 0000 0011₂ (+3) causes signed overflow, even though the unsigned carry‑out is 0.
Box 4 – Logical Shift Multiplication
Shift 0010 1101₂ (45) left by 2 positions. Write the binary result, the hexadecimal equivalent, and the decimal value it now represents.
Box 5 – Adding a Positive and a Negative Number
Add +45₁₀ and –20₁₀ using two’s‑complement. Show each step and state whether any overflow occurs.

Practice Questions (Full‑Mark AO1/AO2)

  1. Add 120₁₀ and 95₁₀** using 8‑bit binary addition. Indicate:
    • Unsigned overflow? (yes/no)
    • Signed overflow? (yes/no)
    • Provide the 8‑bit binary result and its hexadecimal form.
  2. What is the maximum unsigned value that can be stored in an 8‑bit byte? Write it in decimal, binary and hexadecimal.
  3. Convert –45₁₀ to an 8‑bit two’s‑complement binary number and then back to decimal to verify.
  4. Perform a logical left shift of 0010 1101₂ by two positions. What decimal value does the result represent? State whether overflow occurs.
  5. Explain, with reference to the examples above, why a carry‑out from the MSB guarantees unsigned overflow but does **not** always indicate signed overflow.

Suggested Diagram

Column‑wise addition of two 8‑bit binary numbers showing the flow of carries from LSB to MSB
Column‑wise addition of two 8‑bit numbers, illustrating the movement of carry bits.

Summary

  • 8‑bit unsigned range: 0 – 255; signed (two’s‑complement) range: –128 – +127.
  • Binary addition follows simple sum‑and‑carry rules; always track the carry.
  • Unsigned overflow = carry out of the MSB.
  • Signed overflow = carry‑into MSB ≠ carry‑out MSB (or same‑sign addends give a result with opposite sign).
  • Logical shifts provide rapid multiplication/division by powers of two; watch for overflow when shifting left.
  • Conversion fluency (decimal ↔ binary ↔ hexadecimal) is essential for the IGCSE Computer Science exam.

Create an account or Login to take a Quiz

46 views
0 improvement suggestions

Log in to suggest improvements to this note.