Number Systems (AQA A-Level Computer Science): Revision Notes
Number Systems
Introduction
A number is a fundamental unit of mathematical data that we use to count, quantify, label, and measure. In everyday life, we naturally use the decimal system (also called base 10) without thinking about it. However, in computer science, you'll discover that different number systems exist, including binary and hexadecimal, which are covered in later chapters.
In this chapter, we explore various types or sets of numbers and how they're used in computing. Understanding these different categories is essential because computers need to handle numbers in specific ways, and programmers must choose the appropriate number type for their data and operations.
While we naturally use the decimal system in daily life, computers work differently. The decimal system is just one of several number systems you'll encounter in computing. Binary (base 2) and hexadecimal (base 16) are equally important for understanding how computers process and store data.
Natural numbers
Natural numbers are the most familiar numbers we encounter. They're the counting numbers we use every day for ordering and basic arithmetic. These are the numbers formed from the decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
The term "decimal" comes from the fact that we use base 10, meaning there are ten different digits available. With a single digit, we can represent a maximum value of 9. To create larger numbers, we simply add more digits: 10–99 uses two digits, 100–999 uses three digits, and so on, continuing indefinitely.
An important concept to understand is positional value. Each additional digit we add is worth ten times as much as the previous digit because we're working in base 10. This principle is crucial when you later study the binary system, where each position is worth twice the previous one (base 2).
Understanding Positional Value in Base 10
Consider the number 345:
- The 5 is in the "ones" position:
- The 4 is in the "tens" position:
- The 3 is in the "hundreds" position:
Total value:
Each position is worth ten times more than the position to its right. This same principle applies to other number bases, but with different multipliers.
Common Misconception: Does zero count?
There's a common misconception that natural numbers start at 1 and go to 10. In reality, natural numbers begin at 0 and continue to infinity. The inclusion of zero as a natural number has significant implications in computing. For example, when you initialize a counter variable in programming, it typically starts at 0 rather than 1.
The mathematical symbol for natural numbers is ℕ or N, and we can represent them as follows:
The three dots (...) indicate that the sequence continues infinitely.
Integer numbers
An integer is a whole number that can be positive, negative, or zero. Unlike natural numbers, integers extend in both directions from zero. The key characteristic is that integers contain no fractional part and no decimal places - they're complete, whole numbers.
Negative values are indicated by the minus sign (−). There's an important mathematical relationship between negative and positive integers: if you add a number and its negative counterpart, you always get zero. For example:
or equivalently:
Integers are one of the standard data types available when defining variables and constants in programming languages. In theory, there's an infinite number of integers that can be represented. However, in practice, different programming languages have variations of integer types depending on the size of the number that needs to be stored.
Integer Data Types in Programming
For example, in Visual Basic, the Integer type uses four bytes, allowing integers in the range −2,147,483,648 through 2,147,483,647 to be stored. For values outside this range, Visual Basic provides another data type called Long, which can handle larger integers.
Different programming languages offer various integer types to optimize memory usage and accommodate different ranges of values.
The mathematical symbol for integer numbers is ℤ or Z, represented as:
Again, the dots at each end indicate the sequence continues infinitely in both directions.
Rational numbers
A rational number is one that can be expressed as a fraction, also known as a quotient. Fractions consist of two integers, with the value being the ratio between them. This ratio can be expressed either as a fraction or as its decimal equivalent.
For example, we understand as half, which can also be represented as the decimal 0.5. The integer on top is called the numerator, and the integer on the bottom is called the denominator.
The numerator can be any integer, meaning it can be positive, negative, or zero. This flexibility means that the fraction's value can be negative, positive, greater than one, less than one, or equal to zero. Fractions can also result in the value of one. For example:
An important consequence of this definition is that all integers are rational numbers because any integer can be expressed as a fraction with a denominator of 1. For instance, .
Division by Zero - A Critical Programming Concern
There's one critical rule: the denominator can be any integer except zero. Dividing by zero creates an undefined result. You cannot determine how many times 0 goes into 3, for example.
This creates specific problems in computer programming because a program may not be able to continue when it encounters an undefined result. This is called a 'divide by zero' error, and programmers need to be aware of it and prevent it by writing appropriate validation code.
Always validate denominators before performing division operations in your programs!
The mathematical symbol for rational numbers is ℚ or Q.
Irrational numbers
An irrational number is any number that cannot be represented as a ratio of integers because the decimal equivalent would continue forever without repeating. A classic example of an irrational number is (pi). As a fraction, a widely used approximation is . In decimal form, the number is infinite and must be truncated (cut off) to a set number of decimal places. For example, might be rounded to 3.14, or for greater accuracy, to 3.1415926535.
Some square roots and cube roots are also irrational numbers. A square root can be represented as . Starting with a simple example, the square root of 16 is 4. However, if you try to calculate the square root of 2, 3, or 99, you'll find it's impossible to identify a number that, when squared, gives exactly these values. Hence, these square roots are irrational.
Identifying Irrational Square Roots
Let's examine which square roots are rational or irrational:
Rational square roots:
- (because )
- (because )
- (because )
Irrational square roots:
- (continues forever without repeating)
- (continues forever without repeating)
- (continues forever without repeating)
Notice that perfect squares (numbers that are the result of squaring a whole number) have rational square roots, while most other numbers have irrational square roots.
A defining feature of irrational numbers is that the values after the decimal place do not repeat in a pattern. In contrast, some fractions produce recurring decimals that do have a pattern and are therefore classed as rational numbers. For example, one-third = 0.333... recurring (the dots indicate the 3 repeats forever).
Precision and Irrational Numbers in Computing
The implication for computing is significant. When irrational numbers need to be handled, programmers must decide on the level of precision required and, therefore, how much memory to allocate for storing the value. In simple terms, this might mean defining how many decimal places to use.
Computers handle this through specific techniques using fixed and floating point numbers, which are explored in detail in Chapter 25.
Real numbers
A real number is any positive or negative value that can include a fractional part. Integers, rational numbers, and irrational numbers are all categorised as real numbers. The defining feature of a real number is that the fractional part can be any length, allowing the number to represent a measurement to any level of precision and accuracy required.
For example, on a scale between 1 and 10, real numbers enable us to break that down into units of 0.1. On a scale between 0 and 0.1, real numbers allow us to work in units of 0.01, and so on. There's an infinite range of real numbers that can be generated, providing unlimited granularity for measurements.
Real numbers are essential for measuring continuous or infinitely changing values. Consider these computing applications where real numbers are necessary:
Real-World Applications of Real Numbers in Computing
-
A surveyor working on a road may need to take measurements ranging from several kilometres to several metres, for example, 10.15 km.
-
An Olympic race timer for the 100 m may need to handle a range from 8 to 15 seconds accurate to a thousandth of a second, such as 9.934 seconds.
-
A sensor monitoring core temperature in a nuclear power station may need to cope with numbers from 0 to 600 degrees accurate to five decimal places, like 325.65744.
For programmers, the challenge is defining how accurate and precise their numbers need to be for each application. As with irrational numbers, computers handle real numbers using fixed or floating point techniques that are described in detail in Chapter 25.
Ordinal numbers
Ordinal numbers are those that identify the position of something within a list. For example, we use terms like "first, second, and third." Ordinal numbers are often used alongside cardinal numbers, which identify the size of the list. For instance, you might say "you were third out of 20" - here, "third" is the ordinal number (position), and 20 is the cardinal number (total size).
In computing, ordinal numbers are used to identify the position (or location) of data within an ordered set. Consider the following set:
This set is described as well-ordered because it has an internal structure that defines the relationship between the data items. In this example, the data consists of names arranged in ascending alphabetical order. The ordinal number indicates the order of the data, so in this case:
- The first item
- The second item
- The third item , and so on
This technique is particularly useful for locating and manipulating data within certain data structures such as lists, queues, and arrays. Some programming languages support an ordinal data type, which contains a value that can be counted and ordered.
Arrays and ordinal numbers
A one-dimensional array called Register shows a list of names in a register:

Ordinal numbers are used to assign the data as follows:
Register(1) = "Allen"
Register(2) = "Brown"
A table called Exam shows the results for each student:

Using Ordinal Numbers to Access Array Data
Ordinal numbers are used to extract the data as follows:
Exam(1,2) = 50
Exam(2,2) = 75
In this example:
- Exam(1,2) means "the value in row 1, column 2" which is 50
- Exam(2,2) means "the value in row 2, column 2" which is 75
The first number indicates the row (student), and the second number indicates the column (test number). This demonstrates how ordinal numbers provide a systematic way to access specific elements within data structures.
This demonstrates how ordinal numbers provide a systematic way to access specific elements within data structures, making it easier to write programs that process collections of information.
Counting and measurement
As we've explored, the basic use of numbers is to count and measure. We employ different types of numbers in different ways depending on the task at hand.
When counting, we use natural numbers because we only need positive whole numbers. Some common applications in programming include:
- A counter may track how many times a loop statement is repeated
- The program counter in the processor keeps track of which instruction needs to be processed next
- A natural number identifies the location of data within a data structure
- A variable may keep count - for example, of the number of items in a stock control system, or the score in a computer game
When measuring, we use real numbers because the range of numbers may be positive or negative and may require a fractional part. Some examples in programming include:
- CNC machines handle measurements that vary from millimetres to metres and must work to a high degree of accuracy
- Microwave cookers control and measure both time and temperature
- Power stations use data control systems to optimise the production of electricity
- Robotics engineers use real-time measurements of the environment in which the robot is working
Choosing the Right Number Type
Understanding which number type to use is crucial for programmers. Choosing the wrong type could lead to errors, inefficiency, or loss of precision in calculations.
Always consider:
- Will the value ever be negative?
- Does the value need decimal places?
- What range of values might occur?
- How precise does the measurement need to be?
Remember!
Key Points to Remember:
-
Natural numbers are counting numbers starting from zero (0, 1, 2, 3, ...) used in the decimal (base 10) system. They consist of ten different digits: 0 to 9.
-
Integers are whole numbers that can be positive, negative, or zero, with no fractional parts. All integers are also rational numbers.
-
Rational numbers can be expressed as fractions (ratios of two integers). The denominator cannot be zero, as division by zero creates an undefined result and causes errors in programming.
-
Irrational numbers cannot be expressed as fractions because their decimal representation continues infinitely without repeating. Examples include and certain square roots.
-
Real numbers encompass all integers, rational numbers, and irrational numbers. They can represent measurements to any required level of precision and are essential for handling continuous values in computing applications.
-
Ordinal numbers identify position within ordered data structures, while cardinal numbers identify size. Ordinal numbers are crucial when working with arrays, lists, and other data structures in programming.