Sample Notes: Number Systems
O Level and IGCSE Computer Science
Chapter 1.1 – Number Systems
Understanding Binary Representation
- All data in a computer system—text, numbers, images, sound—is stored and processed as binary (base-2).
- Binary is used because computers are made of logic circuits, which operate using two states:
0
(off, low voltage)1
(on, high voltage)
- Logic gates, registers, RAM, and all other components understand only binary inputs and outputs.
Number Systems Overview
Number System | Base | Digits Used | Example |
---|---|---|---|
Denary | 10 | 0 to 9 | 241, 77, 5 |
Binary | 2 | 0, 1 | 10110011 |
Hexadecimal | 16 | 0–9, A–F | 3E, A9, FF |
Conversions Between Number Systems
1. Denary to Binary (positive values only)
- Use division-by-2 method or place value (128, 64, 32, …, 1)
- Example:
13 →00001101
(8 + 4 + 1 = 13)
2. Binary to Denary
- Add place values for all 1s.
- Example:
00011010
→ 16 + 8 + 2 = 26
3. Denary to Hexadecimal
- Use division-by-16 or convert via binary.
- Example:
255 ÷ 16 = 15 remainder 15 →FF
4. Hexadecimal to Denary
- Multiply each digit with corresponding power of 16.
- Example:
1A
= 1×16 + 10 = 26
5. Binary to Hexadecimal
- Break binary into 4-bit groups from the right.
- Convert each group:
1010 1111
→ A F →AF
6. Hexadecimal to Binary
- Convert each digit to 4-bit binary:
2C
→ 2 =0010
, C =1100
→00101100
Why Hexadecimal is Used
- Easier for humans to read and remember than binary:
- 8-bit binary:
11110000
- Equivalent hex:
F0
- 8-bit binary:
- Compact representation
- Widely used in:
- Memory addresses (e.g.,
0x1A3F
) - Color codes in web design (e.g.,
#FF5733
) - Machine code instructions
- Memory addresses (e.g.,
Binary Addition (8-bit only)
Rules
- 0 + 0 = 0
- 1 + 0 = 1
- 1 + 1 = 10 (0 with carry 1)
- 1 + 1 + 1 = 11 (1 with carry 1)
Example
01101010
+ 10101101
= 100101111 (9 bits → overflow occurs)
Overflow in Binary Addition
- Overflow occurs when result exceeds available bits.
- In 8-bit: max value is
11111111
= 255 - Any result > 255 leads to overflow error
- System may store only last 8 bits, leading to incorrect value
- Example:
200 + 100
→ 300 in denary → needs 9 bits → overflow
Logical Binary Shifts
1. Logical Left Shift
- All bits move left; 0 enters from right
- Multiply number by 2 each time
- Example:
00001101
(13) → left shift →00011010
(26)
2. Logical Right Shift
- All bits move right; 0 enters from left
- Divide number by 2 each time
- Example:
00001100
(12) → right shift →00000110
(6)
Effect of Multiple Shifts
- Left shift n times → multiply by 2ⁿ
- Right shift n times → divide by 2ⁿ (integer division)
Two’s Complement Representation (8-bit)
Purpose
- Represents both positive and negative integers in binary.
Steps to Represent Negative Numbers:
- Write positive binary of absolute value.
- Invert all bits (1s → 0s, 0s → 1s)
- Add 1
Example: -18
- +18 =
00010010
- Invert =
11101101
- Add 1 →
11101110
→ This is -18 in two’s complement.
Two’s Complement Ranges
- 8-bit:
- Positive:
00000000
(0) to01111111
(+127) - Negative:
11111111
(-1) to10000000
(-128)
- Positive:
Converting Two’s Complement to Denary
For Positive (starts with 0):
- Same as normal binary.
For Negative (starts with 1):
- Invert all bits
- Add 1
- Convert to denary and place negative sign
Example:
11101110
→ Invert: 00010001
→ Add 1: 00010010
= 18
→ Final: -18