Home Notes Papers

Number systems

Paper 1Paper 2

This section is examined in Paper 1 and Paper 2.

Why Binary?
Computers are built from billions of tiny electronic switches called transistors. Each transistor can exist in one of two stable states: ON (current flows) or OFF (no current). This physical reality maps perfectly to the binary number system, which uses only two digits: 0 and 1.

Using binary is beneficial because:

  • It is physically reliable: Distinguishing between 'on' and 'off' is easier than distinguishing between 10 different voltage levels (as in denary).
  • It reduces noise errors: Electrical interference might change a precise voltage slightly, but it rarely flips a switch from fully ON to fully OFF.

Building on this, all data (text, images, sound) must be converted into binary patterns for the CPU to process.

Number Systems

A number system is defined by its base (or radix), which determines how many unique digits are used and how place values increase.

System Base Digits Used Place Values
Denary (Decimal) 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Powers of 10 (1, 10, 100...)
Binary 2 0, 1 Powers of 2 (1, 2, 4, 8...)
Hexadecimal 16 0-9, A-F Powers of 16 (1, 16, 256...)

Note on Hexadecimal:

  • Digits A to F represent denary values 10 to 15.
  • A=10, B=11, C=12, D=13, E=14, F=15.
Converting Denary to Binary

To convert a positive denary integer to binary, use the powers of 2 method (also known as the subtraction method).

Algorithm:

  1. List powers of 2 (1, 2, 4, 8, 16, 32, 64, 128...) until you exceed the denary number.
  2. Find the largest power of 2 that fits into the denary number. Place a 1 in that position and subtract that value from the denary number.
  3. Move to the next lower power of 2. If it fits into the remaining value, place a 1 and subtract. If it does not fit, place a 0.
  4. Repeat until you reach 2⁰ (the ones column).

Example: Convert Denary 15 to Binary

  • Powers of 2: 8, 4, 2, 1
  • Does 8 fit in 15? Yes. 15 - 8 =
  1. Bit: 1
  • Does 4 fit in 7? Yes. 7 - 4 =
  1. Bit: 1
  • Does 2 fit in 3? Yes. 3 - 2 =
  1. Bit: 1
  • Does 1 fit in 1? Yes. 1 - 1 =
  1. Bit: 1
  • Result: 1111_2
⚠︎ Binary Conversion Padding
Mistake: Writing 101 for denary 5 when the question asks for an 8-bit binary integer.

Correct Understanding:
In computer systems, data is often stored in fixed-size registers (e.g., 8 bits). You must pad with leading zeros to fill the required width.

  • Denary 5 in binary is 101.
  • Denary 5 as an 8-bit integer is 00000101.

Always check if the question specifies a bit-width (e.g., '8-bit'). If it does, ensure your answer has exactly that many digits.

Converting Denary to Hexadecimal

To convert a positive denary integer to hexadecimal, use the division by 16 method.

Algorithm:

  1. Divide the denary number by 16.
  2. Record the remainder. This is the least significant digit (rightmost).
  3. Take the quotient and divide it by 16 again.
  4. Repeat until the quotient is 0.
  5. The hexadecimal value is the sequence of remainders read from bottom to top (last remainder is the most significant digit).

Example: Convert Denary 301 to Hexadecimal

  • 301 ÷ 16 = 18 with a remainder of 13 (D)
  • 18 ÷ 16 = 1 with a remainder of 2
  • 1 ÷ 16 = 0 with a remainder of 1
  • Read remainders upwards: 1, 2, D
  • Result: 12D_{16}
Converting Hexadecimal to Binary

Hexadecimal is a shorthand for binary. Each single hexadecimal digit corresponds exactly to 4 binary bits (a nibble). This makes conversion very fast.

Algorithm:

  1. Break the hexadecimal number into individual digits.
  2. Convert each digit separately into its 4-bit binary equivalent.
  3. Concatenate the groups.
Hex Digit Binary Nibble
0 0000
1 0001
. .
A (10) 1010
E (14) 1110
F (15) 1111

Example: Convert Hex E3 to Binary

  • Digit E (14 in denary) → 1110
  • Digit 3 (3 in denary) → 0011
    Result: 11100011_2
Why Hexadecimal is Beneficial
When to Use: When asked to explain why hexadecimal is used in computing.

Why Examiners Accept This: Hexadecimal is used because it provides a more compact and human-readable representation of binary data. Since each hex digit represents 4 bits, long binary strings (like memory addresses or color codes) are significantly shorter in hex. For example, the 8-bit binary 11100011 is written as just two characters (E3) in hexadecimal. This reduces the chance of transcription errors by humans and makes debugging easier.

Look for phrases like: 'Hexadecimal is more compact than binary' or 'It is easier to read/write than long strings of 0s and 1s'. Avoid saying it is 'faster for the computer'—the CPU processes binary; hex is just a human convenience.

Binary Addition
Binary addition follows the same principles as denary addition but with simpler rules. You carry over when the sum reaches 2 (the base).

Rules:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1-1 + 1 = 10 (write 0, carry 1)
  • 1 + 1 + 1 = 11 (write 1, carry 1)

Example: Add 00110011_2 and 01100001_2
```
Carry: 111111
00110011

  • 01100001
    10010100
    ```
  • Rightmost column: 1+1=10 (write 0, carry 1)
  • Next: 1+0+1=10 (write 0, carry 1)
  • Next: 1+0+0=1 (write 1)
    -...and so on.

Result: 10010100_2

⚠︎ Overflow in Binary Addition
Mistake: Ignoring the carry-out from the Most Significant Bit (MSB) or failing to identify overflow.

Correct Understanding:
In an 8-bit system, the maximum positive value is 11111111_2 (255_{10}). If you add two numbers and the result requires 9 bits (i.e., there is a carry out of the MSB), an overflow has occurred.

  • Why it occurs: The register size is fixed. The extra bit cannot be stored, so the result wraps around or becomes incorrect.
  • Identification: If adding two positive numbers results in a negative-looking number (MSB becomes 1) or if there is a carry out of the MSB that is lost, overflow has happened.

Example:
128 + 129 = 257. In 8-bit binary:
01000000 + 10000001 = 11000001 (with a carry out of 1).
The stored result 11000001 is interpreted as -63 in two's complement, which is wrong. The carry bit was lost.

Describing Overflow
When to Use: When asked to explain why an overflow error occurred.

Why Examiners Accept This: You must state that the result is too large to be stored in the available bits. Specifically, mention that the result exceeds the maximum value representable by the bit-width (e.g., > 255 for 8-bit unsigned integers).

Acceptable phrases include:

  • 'The result is greater than 255.'
  • 'The result cannot be stored in 8 bits.'
  • 'There is a carry out of the MSB that cannot be accommodated.'

Avoid vague answers like 'the computer crashed' or 'it is too big'. Be specific about the bit limit.

Logical Binary Shifts
A logical shift moves all bits in a binary number to the left or right. Zeros are shifted in to fill empty spaces.

Left Shift (\ll):

  • Moves bits to the left by n places.
  • Fills rightmost positions with 0s.
  • Effect: Multiplies the number by 2^n.
  • Example: 101_2 (5_{10}) shifted left by 1 is 1010_2 (10_{10}). 5 \times 2^1 = 10.

Right Shift (\gg):

  • Moves bits to the right by n places.
  • Fills leftmost positions with 0s (for positive integers).
  • Effect: Divides the number by 2^n (integer division, discarding remainders).
  • Example: 1010_2 (10_{10}) shifted right by 1 is 0101_2 (5_{10}). 10 \div 2^1 = 5.

Note: Bits shifted out of the register are lost. This can cause data loss or overflow (in left shifts).

Logical Shift Practice
Q:
Perform a logical left shift of 2 places on the 8-bit binary integer 11100011_2. Show the result.
A:
Shift bits left by 2 positions. The two leftmost bits (11) are lost. Two zeros are added to the right.

Original: 11100011
Shifted: 10001100

Result: 10001100_2

Q:
What is the effect of shifting a positive binary integer to the left by 3 places?
A:
The value is multiplied by 2³ (or 8). Any bits shifted out of the MSB are lost, which may cause overflow.
Two's Complement for Negative Numbers
Computers use two's complement to represent negative integers. This system allows the same hardware used for addition to handle subtraction.

Range of 8-bit Two's Complement:

  • The Most Significant Bit (MSB) is the sign bit.
  • If MSB = 0, the number is positive.
  • If MSB = 1, the number is negative.
  • Range: -128 to +127.

Converting Denary Negative to Two's Complement Binary:

  1. Write the positive denary number in 8-bit binary.
  2. Invert all bits (change 0s to 1s and 1s to 0s). This is called the 'one's complement'.
  3. Add 1 to the result.

Example: Convert -5 to 8-bit two's complement

  1. Positive 5 in binary: 00000101
  2. Invert bits: 11111010
  3. Add 1: 11111010 + 1 = 11111011

Result: 11111011_2

Converting Two's Complement Binary to Denary

To convert a two's complement binary number back to denary, you must determine if it is positive or negative first.

Algorithm:

  1. Check the MSB (leftmost bit).
  • If MSB = 0: The number is positive. Convert normally using powers of 2.
  • If MSB = 1: The number is negative. Proceed to step 2.
  1. Invert all bits (change 0s to 1s and 1s to 0s).
  2. Add 1 to the inverted result.
  3. Convert the resulting binary number to denary.
  4. Apply a negative sign to the final value.

Example: Convert 11110100_2 to Denary

  1. MSB is 1, so it is negative.
  2. Invert bits: 00001011
  3. Add 1: 00001011 + 1 = 00001100
  4. Convert 00001100_2 to denary:
  • 8 + 4 = 12
  1. Apply negative sign: -12_{10}
⚠︎ Two's Complement Range and Overflow

Mistake: Assuming an 8-bit two's complement system can represent +128.

Correct Understanding:
In two's complement, the MSB has a negative weight (-2^7 = -128). The maximum positive value is when all other bits are 1: 01111111_2 = +127.

Therefore:

  • You cannot represent +128 in 8-bit two's complement.
  • Adding two positive numbers that result in an MSB of 1 indicates an overflow because the true sum exceeds +127.
  • The minimum value is 10000000_2, which equals -128 (not -0).
Identifying Two's Complement Errors
When to Use: When asked to identify if a two's complement conversion is correct or to explain an error.

Why Examiners Accept This: Always verify the sign bit. If a question claims 10000000_2 is positive 128, it is incorrect. In two's complement,10000000_2 is -128.

Look for students who explicitly state: 'The MSB is 1, so the number is negative' or 'The range of 8-bit two's complement is -128 to +127'. If a student converts -5 and gets 00000101, they failed to invert/add. The correct method requires showing the inversion step clearly.

Two's Complement Practice
Q:
Convert denary -19 to an 8-bit two's complement binary integer. Show your working.
A:
  1. Positive 19 in binary: 00010011
  2. Invert bits: 11101100
  3. Add 1: 11101100 + 1 = 11101101

Result: 11101101_2

Q:
Convert the two's complement binary number 11010110_2 to denary.
A:
  1. MSB is 1, so it is negative.
  2. Invert bits: 00101001
  3. Add 1: 00101001 + 1 = 00101010
  4. Convert to denary:32 + 8 + 2 = 42
  5. Apply negative sign: -42_{10}
Beta v0.7.8 Free while we're in beta — it transitions to paid post launch. Thank you for supporting us at this stage!