Objectives: Students should be able to —
- 1 Describe how and why computers use binary to represent data.
- 2 Describe denary, binary and hexadecimal number systems.
- 3 Convert numbers between denary, binary and hexadecimal.
- 4 Describe how and why hexadecimal is used for data representation.
- 5 Add two positive 8-bit binary numbers.
- 6 Understand the concept of overflow when performing binary addition.
- 7 Identify and describe uses of binary, signed (2's complement), positive, 8-bit integers.
- 8 Convert between positive denary values into 2's complement binary number.
- 9 Convert positive and negative denary values into 2's complement binary number.
Number Systems: Binary, Denary and Hexadecimal
Computer is made of silicon chips which contain millions of microscopic switches called transistors.
Each switch can only be in one of two states: ON (represented by 1) or OFF (represented by 0).
These ON/OFF states are processed by logic gates inside the CPU.
Therefore, all data must be converted into binary format (1s and 0s) so the computer can process, store and transmit it.
| Analogue Data | Digital Data |
|---|---|
| Continuous change of values | Discrete fixed set of values |
| Represented by a Sine Wave | Represented by a Square Wave |
| Example: human voice, temperature | Example: computer data, binary |
Computers work with digital data only, so analogue data must be converted using an Analogue-to-Digital Converter (ADC).
It is a base 2 numbering system.
It uses only 2 digits: 0 and 1.
Each position represents a power of 2: …2³, 2², 2¹, 2⁰
Example: 1011 = 8 + 0 + 2 + 1 = 11₁₀
It is a base 10 numbering system.
It uses 10 digits: 0 to 9.
Each position represents a power of 10: …10³, 10², 10¹, 10⁰
Example: 345 = 300 + 40 + 5 = 345₁₀
It is a base 16 numbering system.
It uses 16 digits: 0–9 and A–F (where A = 10, B = 11, C = 12, D = 13, E = 14, F = 15).
Each position represents a power of 16: …16³, 16², 16¹, 16⁰
Note: Programmers use this numbering system as it uses very few digits to represent large binary values.
Method: Placeholders method — write the powers of 2 above each binary digit, then add the values where the bit is 1.
Example: Convert 1011011 to denary.
| 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 1 | 0 | 1 | 1 | 0 | 1 | 1 |
Result: 64 + 0 + 16 + 8 + 0 + 2 + 1 = 91₁₀
Method: Successive division by 2 — repeatedly divide the denary number by 2 and record the remainders. Read the remainders from bottom to top.
Example: Convert denary 38 to binary.
| Division | Quotient | Remainder |
|---|---|---|
| 38 ÷ 2 | 19 | 0 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Read remainders from bottom to top: 100110
Method: Group the binary digits into nibbles (groups of 4) starting from the right. Convert each group to its hex digit.
Example: Convert 1010 0111 1101 0101 to hexadecimal.
Result: A7D5₁₆
Method-1: Successive division by 16 — repeatedly divide by 16, record remainders, read from bottom to top.
Example: Convert denary 1453 to hex.
| Division | Quotient | Remainder |
|---|---|---|
| 1453 ÷ 16 | 90 | 13 = D |
| 90 ÷ 16 | 5 | 10 = A |
| 5 ÷ 16 | 0 | 5 |
Read from bottom to top: 5AD₁₆
Method-2: Convert denary → binary → hexadecimal (group binary into nibbles, convert each to hex).
- Hexadecimal uses very few digits to represent long binary numbers.
- Hexadecimal numbers are easy to read, write and remember compared to long binary numbers.
- One hex digit represents exactly 4 bits (one nibble), making conversion straightforward.
- To give MAC addresses for network devices (e.g. 00:1A:2B:3C:4D:5E).
- To give colour codes in HTML documents (e.g. #FF5733).
- To represent error codes generated by programs (e.g. 0x80070005).
- To describe memory locations in a computer.
- Used in assembly language coding.
- Used for memory dumps to trace errors in programs.
- Used in URL encoding to replace unsafe ASCII characters.
Addition of Binary Numbers
(a) Convert to binary:
126 = 01111110
62 = 00111110
(b) Add the two binary values:
Check: 126 + 62 = 188. Binary 10111100 = 128 + 32 + 16 + 8 + 4 = 188. ✓ The result matches.
This addition has generated a 9th bit (carry).
The 8 bits of the answer are 11011100, whose denary value is 220.
However, the correct denary sum is 110 + 110 = 220, which is within the 8-bit range (max 255).
Logical Binary Shifts
(a) Denary value of 01001110:
64 + 8 + 4 + 2 = 78
(b) Logical shifts RIGHT (each shift divides by 2):
| Shift | Binary | Denary |
|---|---|---|
| Original | 01001110 | 78 |
| 1 right | 00100111 | 39 |
| 2 right | 00010011 | 19 |
| 3 right | 00001001 | 9 |
(c) Logical shifts LEFT on denary 52 (00110100):
| Shift | Binary | Denary |
|---|---|---|
| Original | 00110100 | 52 |
| 1 left | 01101000 | 104 |
| 2 left | 11010000 | 208 |
Two's Complement Representation of Signed Numbers
(a) Positional values for 8-bit two's complement:
| -128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The MSB (Most Significant Bit) is the sign bit: 0 = positive, 1 = negative.
(b) Convert binary to denary (two's complement):
- 10110100 → -128 + 32 + 16 + 4 = -76
- 01100110 → 64 + 32 + 4 + 2 = 102
- 10011100 → -128 + 16 + 8 + 4 = -100
- 01110110 → 64 + 32 + 16 + 4 + 2 = 118
(c) Convert denary to 8-bit two's complement:
- +47 → 00101111
- -59 → 11000101
- +89 → 01011001
(d) Convert -45 to binary using two's complement:
Method:
- Convert +45 to binary: 00101101
- Invert all bits (flip 0 ↔ 1): 11010010
- Add 1: 11010011
Verification: Add +45 and -45:
The carry bit is discarded, confirming the result is 0.
Step 1: Convert to 8-bit two's complement:
120 → 01111000
12 → 00001100
Step 2: Add the binary values:
Comment on result:
⚠ Overflow Error has occurred because the sum (132) has exceeded the maximum positive limit of an 8-bit two's complement value, which is 127.
Revision: Statements and Key Computing Terms
| Statement | Key Term |
|---|---|
| The basic computing element that can be either 0 or 1. | Bit |
| The right-most binary digit of a binary number. | Least Significant Bit (LSB) |
| The left-most binary digit of a binary number. | Most Significant Bit (MSB) |
| Shifting binary number 'X' places towards left. | Multiplying by 2^X |
| Shifting binary number 'X' places towards right. | Dividing by 2^X |
| A group of 4 bits. | Nibble |
| A group of 8 bits. | Byte |
| A method of representing negative numbers in binary. | Two's complement |
| The result of a calculation that produces a value too large for the available bits. | Overflow error |