Number systems
This maps perfectly to the binary digits:
- ON = 1
- OFF = 0
Using binary is beneficial because it is reliable and simple. Electronic circuits only need to distinguish between two voltage levels (e.g., high voltage for 1, low voltage for 0). This reduces the chance of errors compared to trying to distinguish between 10 different voltage levels (which would be required for denary/base-10).
Building on this, all forms of data—text, images, sound, and video—are converted into binary sequences before the computer can process them. This is not because computers 'understand' binary in a linguistic sense, but because their hardware physically operates using binary logic gates.
| System | Base | Digits Used | Description |
|---|---|---|---|
| Denary (Decimal) | 10 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | The standard system humans use. Position values are powers of 10 (10^0, 10^1, 10^2...). |
| Binary (Base-2) | 2 | 0, 1 | Used by computers. Position values are powers of 2 (2^0, 2^1, 2^2...). |
| Hexadecimal (Hex) | 16 | 0-9, A-F | Used by programmers. Digits A to F represent denary values 10 to 15. Position values are powers of 16 (16^0, 16^1, 16^2...). |
Note on Hexadecimal Digits:
- A = 10
- B = 11
- C = 12
- D = 13
- E = 14
- F = 15
This relates to binary because one hexadecimal digit represents exactly four binary digits (a nibble). This makes Hex a compact shorthand for long binary strings.
Example: Convert Denary 19 to Binary
| Power of 2 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bit | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 |
Reasoning:
- Does 19 fit in 128? No (0).
- Does 19 fit in 64? No (0).
- Does 19 fit in 32? No (0).
- Does 19 fit in 16? Yes. Subtract 16 from 19, remainder is 3. (Bit = 1)
- Does 3 fit in 8? No (0).
- Does 3 fit in 4? No (0).
- Does 3 fit in 2? Yes. Subtract 2 from 3, remainder is 1. (Bit = 1)
- Does 1 fit in 1? Yes. Remainder is 0. (Bit = 1)
Result: 00010011_2
Examiner Tip: Always write the bits in the correct column order. A common mistake is writing the binary string backwards or skipping columns.
The Correct Understanding: You can convert Denary to Hex directly by repeated division by 16, which is often faster and less prone to transcription errors than going through binary.
Example: Convert Denary 267 to Hexadecimal
- 267 \div 16 = 16 remainder 11 (which is B)
- 16 \div 16 = 1 remainder 0
- 1 \div 16 = 0 remainder 1
Read the remainders from bottom to top: 10B_{16}.
Why this matters: If you convert via binary (267 = 100001011_2), you must pad with leading zeros to make groups of 4: 0001\ 0000\ 1011. Then 1=1, 0=0, 11=B. Both methods yield 10B, but the division method is more direct.
Correct Phrasing: "Hexadecimal provides a shorter, more human-readable representation of binary data."
Reasoning: Examiners accept this because it addresses the practical utility for programmers. A 32-bit memory address like 11110000111100001111000011110000_2 is difficult to read and prone to transcription errors. In Hex, this is F0F0F0F0_{16}, which is much easier to debug and verify.
Example Usage: "Programmers use hexadecimal because it takes up less screen space and is easier for humans to spot errors compared to long strings of binary digits."
Working:
| Carry | 1 | 1 | 1 | 1 | ||||
|---|---|---|---|---|---|---|---|---|
| Bit 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
| Bit 2 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Sum | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
Result: 11010101_2
Mark Scheme Key Points:
- Correct application of binary addition rules (1+1=10_2, i.e., write 0 carry 1).
- Final answer 11010101_2.
In 8-bit signed integers (using two's complement), the range is -128 to +127. If you add two positive numbers and the result exceeds 127, or add two negative numbers and the result is less than -128, overflow has occurred.
How to detect it visually:
- Look at the Most Significant Bit (MSB) (the leftmost bit). In signed binary, the MSB indicates the sign (0 for positive, 1 for negative).
- If you add two positive numbers (both start with 0) and the result starts with 1, overflow has occurred.
- Alternatively, if you add two negative numbers (both start with 1) and the result starts with 0, overflow has occurred.
Example:
Add +100 (01100100_2) and +50 (00110010_2).
Sum = 10010110_2. The MSB is 1, indicating a negative number. Since we added two positives, the result should be positive. The overflow bit (carry out of the MSB) is often ignored in simple signed arithmetic checks, but the sign error confirms overflow.
A logical shift moves all bits in a binary integer to the left or right. Zeros are shifted in from the opposite side.
| Shift Type | Direction | Effect on Positive Integer | Note |
|---|---|---|---|
| Logical Left Shift | Left (\ll) | Multiplies the value by 2^n (where n is the number of shifts). | Bits shifted out of the MSB are lost. If a 1 is shifted out, the magnitude changes significantly. |
| Logical Right Shift | Right (\gg) | Divides the value by 2^n (integer division, discarding remainder). | Bits shifted out of the LSB are lost. This reduces precision. |
Constraint for Positive Integers:
For a positive 8-bit integer, the MSB is always 0.
- A left shift is safe as long as the new MSB remains 0 (i.e., no overflow into the sign bit). If the MSB becomes 1, the number is interpreted as negative in two's complement.
- A right shift preserves the positive sign (MSB stays 0) but loses data from the right.
- 0 = Positive
- 1 = Negative
Representing a POSITIVE Integer:
To represent a positive integer, simply convert it to binary and pad with leading zeros so the MSB is 0. It looks identical to unsigned binary.
Example: Represent +5 in 8-bit two's complement.
- Denary 5 in binary is 101_2.
- Pad to 8 bits: 00000101_2.
- Check MSB: It is 0, so it is positive. Correct.
Representing a NEGATIVE Integer:
To represent -N, take the binary of +N, invert all bits (flip 0s to 1s and 1s to 0s), then add 1.
Example: Represent -22 in 8-bit two's complement.
- Denary 22 in binary: 00010110_2.
- Invert bits: 11101001_2.
- Add 1: 11101001 + 1 = 11101010_2.
- Check MSB: It is 1, so it is negative. Correct.
Why this works: The MSB in two's complement has a negative weight. In an 8-bit number, the weights are:
-128, +64, +32, +16, +8, +4, +2, +1.
For 11101010_2: -128 + 64 + 32 + 16 + 0 + 4 + 0 + 0 = -128 + 116 = -12. Wait, let's re-calculate.
-128 + 64 + 32 + 16 + 4 + 2 = -128 + 118 = -10? No.
Let's check -22 again.
+22 = 00010110.
Flip: 11101001.
Add 1: 11101010.
Value: -128 + 64 + 32 + 16 + 0 + 4 + 0 + 0 = -128 + 116 = -12.
Correction: My manual calculation in the example step was wrong. Let's re-verify +22.
16 + 4 + 2 = 22. Correct.
Flip: 11101001.
Add 1: 11101010.
Sum of positive weights: 64+32+16+4+2 = 118.
-128 + 118 = -10.
Wait, where is the error?
Ah, 22 = 16 + 4 + 2. Binary: 00010110.
Flip: 11101001.
Add 1: 11101010.
Weights: -128, 64, 32, 16, 8, 4, 2, 1.
Bits: 1, 1, 1, 0, 1, 0, 1, 0.
Sum: -128 + 64 + 32 + 0 + 8 + 0 + 2 + 0 = -128 + 106 = -22.
Correct. The bit at position 8 (value 8) is 1. In my previous line I wrote 0 for that position. The binary is 11101010. Positions: 7(-128), 6(64), 5(32), 4(16), 3(8), 2(4), 1(2), 0(1).
Bits: 1, 1, 1, 0, 1, 0, 1, 0.
-128 + 64 + 32 + 8 + 2 = -128 + 106 = -22. Correct.
The Correct Understanding: In 8-bit two's complement, the MSB has a weight of -128, not +128.
If you are given a negative two's complement number like 11101010_2, you must calculate:
(-1 \times 128) + (1 \times 64) + (1 \times 32) + (0 \times 16) + (1 \times 8) + (0 \times 4) + (1 \times 2) + (0 \times 1).
Common Mistake: Converting -22 by taking binary 22 (00010110) and just changing the first bit to 1 (10010110). This is incorrect. You must invert all bits then add 1.
Correct Phrasing: "Each hexadecimal digit corresponds to a 4-bit nibble."
Reasoning: Examiners look for the direct mapping relationship. You do not need to go through denary.
- F_{16} = 1111_2
- A_{16} = 1010_2
- 0_{16} = 0000_2
Example Usage: "To convert Hex to Binary, replace each hex digit with its 4-bit binary equivalent. To convert Binary to Hex, group the bits into sets of four starting from the right, then convert each nibble to its hex digit."
Original: 00101100_2 (44_{10})
Shift Left 1: 01011000_2 (88_{10})
Shift Left 2: 10110000_2
Denary Result:
10110000_2 = 128 + 32 + 16 = 176_{10}.
Effect Explanation: The value has been multiplied by 4 (2^2). 44 \times 4 = 176.
Note: In this specific case, the MSB became 1, which would make it a negative number in two's complement signed arithmetic. However, as a positive unsigned integer or logical shift, the magnitude is simply multiplied by 2^n.