Data Representation and Multimedia: Question 3

Syllabus 1.1, 1.2, 1.3

Structured AS 8 marks

A microcontroller uses an 8-bit register and represents signed integers using two's complement.

(a) Convert the denary number -45 into its 8-bit two's complement binary representation. Show your method (convert +45 to binary, then invert the bits and add 1). [3]

(b) The register adds the two 8-bit binary values 01100100 and 01011010. Show the binary addition bit by bit and give the 8-bit result. [2]

(c) The two binary values added in part (b) represent the denary numbers 100 and 90, both stored as positive two's complement numbers. By examining the sign bit of your 8-bit result from part (b), state whether overflow has occurred, and explain how you can tell. [3]

Show worked solution Hide worked solution

Worked solution

Part (a): -45 in 8-bit two’s complement

Step 1, write +45 in 8-bit binary. Using bit values 128, 64, 32, 16, 8, 4, 2, 1:

32 + 8 + 4 + 1 = 45

So +45 = 00101101.

Step 2. Invert every bit (change each 0 to 1 and each 1 to 0):

00101101  ->  11010010

Step 3. Add 1 to the inverted value:

  11010010
+ 00000001
-----------
  11010011

So -45 in 8-bit two’s complement is 11010011. [3 marks]: [1] for the correct binary of +45 (00101101), [1] for correctly inverting all 8 bits, [1] for correctly adding 1 to reach 11010011.

(Check: 11010011 has sign bit 1, so it represents a negative number. The remaining bits 1010011 are worth 64+16+2+1 = 83, so the value is -128 + 83 = -45, confirming the result.)

Part (b): Adding 01100100 and 01011010

Add the two 8-bit values column by column from the rightmost bit, carrying into the next column whenever a column sums to 2 or more.

Working bit by bit (bit 0 is rightmost):

  • Bit 0: 0 + 0 = 0, carry 0
  • Bit 1: 0 + 1 = 1, carry 0
  • Bit 2: 1 + 0 = 1, carry 0
  • Bit 3: 0 + 1 = 1, carry 0
  • Bit 4: 0 + 1 = 1, carry 0
  • Bit 5: 1 + 0 = 1, carry 0
  • Bit 6: 1 + 1 = 0, carry 1
  • Bit 7: 0 + 0 + (carry 1) = 1, carry 0
    0 1 1 0 0 1 0 0
  + 0 1 0 1 1 0 1 0
  -----------------
    1 0 1 1 1 1 1 0

So the 8-bit result is 10111110. [2 marks]: [1] for working that correctly propagates carries between columns, [1] for the correct final 8-bit result 10111110.

Part (c): Detecting overflow

01100100 and 01011010 both have sign bit 0, so both are stored as positive two’s complement numbers (denary 100 and 90).

The result from part (b), 10111110, has sign bit 1. By the rules of two’s complement, this means the 8-bit register is interpreting the result as a negative number.

Two genuinely positive numbers can never sum to a negative number. The true denary sum, 100 + 90 = 190, is outside the range an 8-bit signed two’s complement register can hold (-128 to +127), so it cannot be represented correctly. This is exactly what overflow means.

A more formal check confirms it: the carry generated into the sign bit (from adding bit 6: 1 + 1 = 0, carry 1) is 1, but the carry generated out of the sign bit (from adding bit 7: 0 + 0 + 1 = 1, no further carry) is 0. Because the carry into the sign bit does not equal the carry out of the sign bit, overflow has occurred.

[3 marks]: [1] for stating that overflow has occurred, [1] for identifying that the result’s sign bit is 1 despite both operands being positive (or the equivalent carry-in/carry-out mismatch), [1] for linking this to the true sum (190) being outside the representable 8-bit signed range.

Final answers

  • (a) -45 = 11010011
  • (b) 01100100 + 01011010 = 10111110
  • (c) Overflow has occurred (the result’s sign bit incorrectly shows 1 for a sum of two positive numbers)