1.1 Number Systems: The Foundation of Computer Data

Hello! This chapter is where we learn the secret language of computers. Everything you see on your screen—text, images, sound, and numbers—must first be turned into a sequence of electrical pulses that the computer can understand. This process is called Data Representation.

Don't worry if the math looks strange; we break down every conversion into easy, step-by-step tricks!

Why Computers Only Speak Binary (Base 2)

Humans use the Denary system (Base 10) because we have 10 fingers. Computers, however, operate using electricity. A computer only needs to distinguish between two states: ON or OFF.

  • ON is represented by the digit 1.
  • OFF is represented by the digit 0.

Because it only uses two digits (0 and 1), this is called the Binary system (Base 2).

Key Term: A single binary digit (0 or 1) is called a Bit. Computers store these bits in temporary storage areas called Registers.


Quick Review: Number Systems to Know
  • Denary (Decimal): Base 10 (Uses digits 0–9). This is the system we use every day.
  • Binary: Base 2 (Uses digits 0 and 1). The native language of computers.
  • Hexadecimal (Hex): Base 16 (Uses digits 0–9 and letters A–F). A helpful shortcut for programmers.

2. Conversions Between Number Systems

We need to be able to switch between these three bases. Remember: No calculators are allowed, so understanding the column headings is vital!

2.1 Denary (Base 10) and Binary (Base 2) Conversions

In any number system, the position of a digit gives it a value. In binary, these are powers of 2. We typically use 8 bits (one Byte) for representation, but the syllabus requires up to 16 bits.

The 8-bit column headings are:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1

A. Denary to Positive Binary Conversion

We use the subtraction method. Start with the largest column value that is less than or equal to your Denary number.

Example: Convert Denary 195 to 8-bit Binary.

  1. Is 195 $\ge$ 128? Yes. Put a 1 under 128. Remaining: \(195 - 128 = 67\).
  2. Is 67 $\ge$ 64? Yes. Put a 1 under 64. Remaining: \(67 - 64 = 3\).
  3. Is 3 $\ge$ 32? No. Put a 0.
  4. Is 3 $\ge$ 16? No. Put a 0.
  5. Is 3 $\ge$ 8? No. Put a 0.
  6. Is 3 $\ge$ 4? No. Put a 0.
  7. Is 3 $\ge$ 2? Yes. Put a 1. Remaining: \(3 - 2 = 1\).
  8. Is 1 $\ge$ 1? Yes. Put a 1. Remaining: \(1 - 1 = 0\).

The 8-bit binary result is 11000011.

B. Positive Binary to Denary Conversion

Simply multiply the column value by the binary digit (0 or 1) and add up the results.

Example: Convert Binary 01010101 to Denary.

1286432168421
01010101

Calculation: \((0 \times 128) + (1 \times 64) + (0 \times 32) + (1 \times 16) + (0 \times 8) + (1 \times 4) + (0 \times 2) + (1 \times 1)\)
\(= 0 + 64 + 0 + 16 + 0 + 4 + 0 + 1 = 85\)

The Denary result is 85.


2.2 Denary (Base 10) and Hexadecimal (Base 16) Conversions

Hexadecimal uses 16 symbols. We need new symbols for the numbers 10 through 15:

A = 10, B = 11, C = 12, D = 13, E = 14, F = 15

A. Denary to Hexadecimal Conversion

Use the division method. Divide the Denary number by 16.

Example: Convert Denary 250 to Hex.

  1. Divide 250 by 16: \(250 \div 16 = 15\) with a remainder of \(10\).
  2. Convert the remainder (10) to its Hex symbol: A. This is the Least Significant Digit (LSD).
  3. Take the quotient (15) and convert it to its Hex symbol: F. This is the Most Significant Digit (MSD).

The Hex result is FA.

B. Hexadecimal to Denary Conversion

The columns in Hex are powers of 16 (\(16^0=1\), \(16^1=16\), \(16^2=256\), etc.).

Example: Convert Hex 3F to Denary.

  1. Break down the Hex digits: 3 and F. Remember F = 15.
  2. Multiply the column value by the digit's Denary equivalent.
    \((3 \times 16) + (F \times 1)\)
    \((3 \times 16) + (15 \times 1)\)
    \(= 48 + 15 = 63\)

The Denary result is 63.


2.3 Hexadecimal and Binary Conversions (The Easiest One!)

Since \(16 = 2^4\), one Hex digit can always be perfectly represented by exactly 4 Binary bits (a nibble). This is the 'shortcut' conversion.

A. Hexadecimal to Binary Conversion

Convert each Hex digit into its 4-bit Binary equivalent.

Example: Convert Hex A5 to Binary.

  1. Separate the digits: A and 5. (A = 10 in Denary).
  2. Convert A (10) using the 4-bit column headings (8, 4, 2, 1): \(8+2 = 10 \rightarrow \mathbf{1010}\)
  3. Convert 5 using the 4-bit column headings (8, 4, 2, 1): \(4+1 = 5 \rightarrow \mathbf{0101}\)

Combine the results: 10100101.

B. Binary to Hexadecimal Conversion

Group the binary number into blocks of 4 bits starting from the right, and then convert each group to a single Hex digit.

Example: Convert Binary 11110011 to Hex.

  1. Group:
    \(\mathbf{1111} \ \ \ \ \ \ \ \ \mathbf{0011}\)
  2. Convert the left group (\(1111\)): \(8+4+2+1 = 15\). Hex symbol: F.
  3. Convert the right group (\(0011\)): \(2+1 = 3\). Hex symbol: 3.

The Hex result is F3.

Key Takeaway: Conversions

Hex is just a convenient shortcut for Binary. If you need to convert Denary to Binary (or vice versa) via Hex, use Denary $\leftrightarrow$ Hex, and then Hex $\leftrightarrow$ Binary. The shortcut step is always dividing the binary string into nibbles (4 bits).

3. The Purpose of Hexadecimal

3.1 Understanding the Benefit

Why bother with Hex when computers use Binary and humans use Denary?

Hexadecimal is used as a beneficial method of data representation because:

  1. It is shorter: Hexadecimal provides a much shorter representation of long binary strings. A 16-bit binary number (e.g., 1101001011110000) becomes just four Hex digits (D2F0). This reduces errors when humans are transcribing or reading data.
  2. It is easier for humans: It is far simpler for a programmer to read and remember 'A4' than to read and remember '10100100'.

3.2 Where Hex is Used in Computer Science

You will find Hexadecimal used in several areas:

  • MAC Addresses: The unique physical address of a network card (e.g., 00-1A-C2-7B-00-47).
  • Memory Dumps: When a programmer needs to inspect the raw contents of memory (registers or RAM), the data is displayed in Hex for readability.
  • HTML Colour Codes: Colours on websites are often represented by six Hex digits (e.g., #FF0000 is pure red).

4. Binary Arithmetic: Addition and Overflow

4.1 Adding Two Positive 8-bit Binary Integers

Binary addition follows simple rules. You only ever deal with 0s and 1s:

  • \(0 + 0 = 0\)
  • \(1 + 0 = 1\)
  • \(1 + 1 = 0\) carry 1 (like 5+5=0 carry 1 in Denary)
  • \(1 + 1 + 1 = 1\) carry 1

Example: Add Binary 01010010 (82) and 00001011 (11).

     Carry Row: 1 1
  01010010 (82)
+ 00001011 (11)
----------
  01011101 (93)

4.2 Understanding the Concept of Overflow

An overflow error occurs when the result of a calculation is too large to fit into the allocated storage space (the register).

In the IGCSE syllabus, we focus on 8-bit registers.

  • The largest positive integer an 8-bit register can hold is 11111111 (which is 255 in Denary).
  • If you add two numbers and the result requires a 9th bit, an overflow has occurred.

Example of Overflow: Add 150 and 150 (both fit in 8 bits). Result should be 300.

     Carry Row: 1 1 1 1 1 1
  10010110 (150)
+ 10010110 (150)
----------
$\mathbf{1}\ $ 00101100 (44)

The 9th bit (in bold) is called the overflow bit. Since the register only has space for 8 bits, the computer will only store 00101100 (44), giving an incorrect answer and triggering an overflow error.

Analogy: Imagine pouring 300 ml of juice into a glass that can only hold 255 ml. The excess juice spills over, and the glass (the register) only holds the maximum amount, missing the true result.

Memory Aid: Overflow

If the total Denary value is greater than 255, you will get an overflow when using an 8-bit register.

5. Specialized Binary Techniques

5.1 Logical Binary Shifts

A logical binary shift is a quick operation that moves all the bits in a register either to the left or to the right.

When a shift is performed:

  • Bits shifted out of the end of the register are lost.
  • The empty spots created at the opposite end are filled with zeros.
A. Logical Left Shift

Shifting left is equivalent to multiplying the number by a power of 2.

Rule: For every one position shifted left, the number is multiplied by 2.

Example: Binary 00000101 (5). Shifted left by 2 places.

  • Two bits (00) are shifted in from the right.
  • The two most significant bits (00) are shifted out and lost.


\(00000101 \rightarrow \mathbf{00010100}\) (Denary 20).
(Original value 5 is multiplied by \(2^2\), or 4, resulting in 20).

B. Logical Right Shift

Shifting right is equivalent to dividing the number by a power of 2.

Rule: For every one position shifted right, the number is divided by 2.

Example: Binary 00101000 (40). Shifted right by 3 places.

  • Three zeros (000) are shifted in from the left.
  • The three least significant bits (000) are shifted out and lost. (This results in integer division, discarding any remainder).


\(00101000 \rightarrow \mathbf{00000101}\) (Denary 5).
(Original value 40 is divided by \(2^3\), or 8, resulting in 5).

Did You Know?

Shifts are incredibly fast for multiplication and division. Computers use shifting instead of traditional arithmetic to perform these calculations quickly in assembly language.

5.2 Two's Complement: Representing Negative Numbers

So far, we have only looked at positive integers (0 to 255). How does a computer represent a negative number? It uses Two's Complement.

Two's complement allows us to store both positive and negative integers in the same register.

The Sign Bit

When using two's complement (in our 8-bit example):

  • The Most Significant Bit (MSB) (the leftmost bit, column 128) becomes the Sign Bit.
  • If the MSB is 0, the number is Positive.
  • If the MSB is 1, the number is Negative.

The maximum range for 8-bit two's complement is -128 to +127.

Conversion Steps (Positive Denary to Negative Two's Complement)

To convert a Denary number (e.g., -42) into its 8-bit two's complement representation:

Step 1: Write the positive binary number.
\(42 = 00101010\)

Step 2: Find the One's Complement (FLIP the bits).
Change every 0 to 1 and every 1 to 0.
\(00101010 \rightarrow \mathbf{11010101}\)

Step 3: Add 1.
  11010101
+               1
----------
  \(\mathbf{11010110}\)

The 8-bit two's complement for -42 is 11010110. (Note the MSB is 1, indicating a negative number).

Conversion Steps (Negative Two's Complement back to Denary)

To convert a negative binary number (e.g., 11010110) back to Denary:

Step 1: Find the One's Complement (FLIP the bits).
\(11010110 \rightarrow 00101001\)

Step 2: Add 1.
  00101001
+               1
----------
  00101010

Step 3: Convert the resulting positive binary to Denary.
\(00101010 = 32 + 8 + 2 = 42\)

Since we started with a negative sign bit (1), the original number must be -42.


Chapter Summary: Key Takeaways
  • Binary is Base 2 (0s and 1s), used because computers rely on two electrical states (ON/OFF).
  • Hexadecimal (Base 16) is a shorthand notation for binary, making long binary strings manageable for humans (4 bits = 1 Hex digit).
  • Binary addition involves carrying 1 when adding \(1+1\).
  • Overflow occurs in 8-bit addition if the result exceeds the maximum value of 255 (a 9th bit is generated and lost).
  • Left shifts multiply by 2; Right shifts divide by 2. Zeros fill the gaps.
  • Two's Complement is used to represent negative numbers. The MSB (leftmost bit) is the sign bit.