SLIDE 1 / 10
CSZone.co.uk
OCR H446 · Component 1 · 1.4.1

Two's Complement,
Binary Arithmetic & Hex

OCR A Level Computer Science · cszone.co.uk
H446 SpecA Level
Learning Objectives

By the end of this topic you will be able to:

Represent negative numbers using two's complement
Convert between two's complement binary and denary
Perform binary subtraction using two's complement addition
Perform arithmetic shifts left and right on binary numbers
Two's Complement

Representing Negative Numbers

In two's complement, the most significant bit (MSB) has a negative weight. For an 8-bit number: MSB = −128, then 64, 32, 16, 8, 4, 2, 1. This allows one encoding for zero and arithmetic using the same circuits as unsigned addition.
Method: Positive → Negative
To negate a number:
1. Invert all bits (one's complement)
2. Add 1

Example: +45 = 0010 1101
Invert: 1101 0010
Add 1: 1101 0011 = −45
Range for n bits
8-bit two's complement range:
−128 to +127

Formula: −2^(n−1) to 2^(n−1) − 1

The MSB = 1 indicates a negative number. The MSB = 0 indicates non-negative.
Reading Two's Complement

Converting Two's Complement → Denary

If MSB = 0: read as normal unsigned binary (positive number).
If MSB = 1: the number is negative. Use the negative MSB weight: −128+… or use the negate-and-convert trick.
Method 1: Direct Weights
1101 0011
−128+64+0+16+0+0+2+1
= −128 + 83
= −45
Method 2: Negate Then Convert
1101 0011
Invert: 0010 1100
Add 1: 0010 1101 = 45
Therefore original = −45
Both methods give the same result. Method 1 is faster once you are comfortable; Method 2 avoids mistakes with the negative MSB weight.
Binary Subtraction

Subtraction Using Two's Complement

Computers perform subtraction as addition of the two's complement. To compute A − B: negate B (two's complement), then add A + (−B). Any carry out of the MSB is discarded.
Example: 25 − 10
+25 = 0001 1001
+10 = 0000 1010
−10 = 1111 0110 (two's comp)

0001 1001
+ 1111 0110
──────────
(1)0000 1111 = 15 ✓
Carry discarded
Arithmetic Shifts
Shift left 1 bit = multiply by 2 (fill right with 0).
Shift right 1 bit = divide by 2 (fill left with sign bit — preserves sign in two's complement).

1100 1010 >> 1 = 1110 0101 (sign extended)
1100 1010 << 1 = 1001 0100 (may overflow)
Hex Arithmetic

Hexadecimal Addition

Add hex digits column by column. If the sum ≥ 16, write (sum − 16) in hex and carry 1 to the next column.
  4 A 7
+  2 F 9
─────────
7 + 9 = 16 → write 0, carry 1
A + F + 1 = 10 + 15 + 1 = 26 = 16+10 → write A, carry 1
4 + 2 + 1 = 7 → write 7
Result: 7 A 0
Check: 4A7 hex = 1191 denary; 2F9 hex = 761 denary; 1191+761=1952; 7A0 hex = 1952 denary ✓
Exam Practice
OCR H446 Style · 5 marks
(a) Express −73 as an 8-bit two's complement binary number. [2 marks]
(b) Use two's complement addition to calculate 100 − 73, showing all working. [3 marks]
[5 marks]
2
(a) +73 = 0100 1001. Invert: 1011 0110. Add 1: 1011 0111 = −73
1
(b) 100 = 0110 0100. −73 = 1011 0111.
1
Add: 0110 0100 + 1011 0111 = (1)0001 1011. Carry out of MSB discarded.
1
0001 1011 = 16+8+2+1 = 27. Correct: 100−73=27 ✓
Common Mistakes

Don't Lose Marks

!
Forgetting to add 1 when finding two's complement — invert all bits (one's complement) is NOT the same as two's complement. Always invert then add 1. Students frequently stop after inverting and lose marks.
!
Saying a right arithmetic shift fills with 0 — for a signed two's complement number, arithmetic right shift fills with the sign bit (1 for negative). This preserves the sign. Logical right shift fills with 0, but that changes negative numbers to positive.
!
Not discarding the carry out in two's complement subtraction — when the carry propagates out of the MSB in two's complement addition, it should be discarded. The remaining 8 bits are the correct signed result. Not discarding it gives a wrong answer.
1.4.1b Complete
Well done! ✓
Two's Complement, Binary Arithmetic and Hexadecimal
Return to lesson to continue