You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers how computers represent signed integers using two's complement and how fixed-point binary is used to represent fractional numbers. Both are required for the OCR H446 specification.
Computers need to represent both positive and negative integers. Since binary only has 0s and 1s, a convention is needed to distinguish between positive and negative values.
| Method | Description | Used in Practice? |
|---|---|---|
| Sign and magnitude | The MSB is the sign (0 = positive, 1 = negative); remaining bits = magnitude | Rarely — has +0 and -0 |
| One's complement | Negative = flip all bits of the positive value | Rarely — has +0 and -0 |
| Two's complement | Negative = flip all bits and add 1 | Yes — standard method |
Two's complement is the standard because:
In an n-bit two's complement system:
| -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| MSB (sign bit) | LSB |
For an n-bit two's complement number:
| Bits | Minimum | Maximum |
|---|---|---|
| 8 | -128 | +127 |
| 16 | -32,768 | +32,767 |
| 32 | -2,147,483,648 | +2,147,483,647 |
If the number is positive, convert to binary as normal. The MSB will be 0.
Example: +45 in 8-bit two's complement = 00101101
Step 1: 73 in binary = 01001001 Step 2: Flip all bits = 10110110 Step 3: Add 1 = 10110111
-73 in two's complement = 10110111
| -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 |
-128 + 32 + 16 + 4 + 2 + 1 = -128 + 55 = -73. Correct.
If the MSB is 0, the number is positive — convert as normal.
If the MSB is 1, the number is negative — add up all place values, remembering the MSB represents a negative value.
| -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
-128 + 64 + 32 + 2 = -30
If the MSB is 1:
11100010 -> flip -> 00011101 -> add 1 -> 00011110 = 30
So the original = -30
The beauty of two's complement is that addition works the same regardless of sign.
25 = 00011001
-10 = 11110110
00011001
+ 11110110
──────────
00001111 = 15
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.