TutorChase logo
Login
AQA A-Level Computer Science

14.1.2 Integer numbers

Integers are a foundational concept in both mathematics and computer science, forming the basis for many operations and representations. They include positive and negative whole numbers, including zero, and are used in a wide range of computational tasks such as indexing, counting, storing values, and controlling logic. Understanding how integers behave and are used in programming is critical for developing efficient, accurate, and bug-free code.

What are integers?

Definition of integers

An integer is any whole number that can be positive, negative, or zero. Integers do not include fractions or decimal values; they consist only of full, indivisible units. This characteristic makes them particularly useful in areas such as counting, indexing, and logical operations.

The set of integers is denoted by the symbol , which comes from the German word Zahlen, meaning “numbers.”

Standard notation:

ℤ = { ..., -3, -2, -1, 0, 1, 2, 3, ... }

This set is infinite in both directions—there is no largest or smallest integer. Integers are an example of a countably infinite set.

Characteristics of integers

  • Whole values only — no decimals or fractional components

  • Can be positive, negative, or zero

  • Positioned on a number line, extending infinitely in both directions

Take your grades to the next level!

UPGRADING TO PREMIUM UNLOCKS
AI Tutor
AI-powered study assistant
instant feedback and guidance
Predicted Papers
Examiner-style predicted papers
based on recent exam trends
Practice Questions
All exam practice questions
by topic for each subject
Study Notes
All detailed revision notes
written by expert teachers
Cheat Sheets
Quick revision summaries
perfect for last-minute review
Past Papers
Complete collection
of practice and past exam papers
Email
Password
Confirm Password
Already have an account?

Practice Questions

FAQ

Zero-based indexing is used in most programming languages because it aligns directly with how memory addresses are calculated. In a zero-based system, the index directly corresponds to an offset from the base memory address. For example, the element at index 0 is located at the base address, the element at index 1 is at base + 1 unit (depending on element size), and so on. This makes address calculation simple and efficient using pointer arithmetic. It avoids an extra subtraction operation that would be needed in a one-based system. Additionally, zero-based indexing was popularised by languages like C, which had a strong influence on many modern programming languages. It simplifies certain looping and conditional expressions and reduces the chances of off-by-one errors in iterative constructs. Although one-based indexing may feel more intuitive for humans, zero-based indexing is computationally efficient and has become the standard in most high-level and low-level programming environments.

A literal integer is a fixed value written directly into the code, such as 42 or -7. It is a constant and cannot change while the program is running. Literal integers are used when the value is known in advance and does not need to be stored or manipulated independently. On the other hand, an integer variable is a named storage location that can hold different integer values over time. For example, int count = 42; creates a variable named count that is initially assigned the literal value 42. Variables are mutable, meaning they can be updated throughout the execution of a program. Literal integers are used for fixed values like array sizes, whereas variables are used for dynamic values like counters, user input, and calculations. Understanding this distinction is essential for managing memory, writing efficient code, and distinguishing between static and dynamic behaviours in programs.

The number of bits assigned to store an integer directly determines the range of values it can represent. Each additional bit doubles the number of distinct values that can be stored. For an unsigned integer with n bits, the range is from 0 to (2^n) - 1. For a signed integer using two’s complement, the range is from -2^(n-1) to (2^(n-1)) - 1. For example, an 8-bit signed integer has a range from -128 to 127, while a 16-bit signed integer ranges from -32,768 to 32,767. Choosing a bit size that is too small can lead to overflow or truncation errors, whereas choosing one that is too large may waste memory. In performance-sensitive applications, especially in embedded systems or game development, choosing the most efficient bit size is critical. Languages like C and C++ allow fine-grained control over bit sizes, while higher-level languages often abstract this detail away.

Integer overflow occurs when the result of an operation exceeds the maximum value that can be represented by the given number of bits. For example, adding 1 to a 32-bit signed integer at its maximum value of 2,147,483,647 results in wraparound to -2,147,483,648 due to two’s complement behaviour. This can lead to logic errors, incorrect calculations, or security vulnerabilities such as buffer overflows. Prevention methods include using larger data types (e.g. moving from 32-bit to 64-bit integers), implementing range checks before operations, or using special libraries and language features that provide safe arithmetic. Some programming languages (e.g. Rust or Swift) offer built-in overflow detection, while others (like C) do not. Compilers may also offer flags to enable overflow checking during development. Ultimately, being aware of bit limits and applying defensive programming techniques is essential when dealing with arithmetic operations on integers.

Programming languages often provide multiple integer types like short, int, long, and their unsigned variants to give developers more control over memory usage and performance. Each type has a different bit width—typically 16 bits for short, 32 bits for int, and 64 bits for long, though these sizes may vary between systems. A smaller type like short consumes less memory, which is useful in memory-constrained environments like embedded systems. A larger type like long can store bigger numbers, which is necessary for calculations involving large ranges or data aggregation. Distinguishing between these types allows programmers to optimise for speed and efficiency. However, using the wrong type may result in overflow or wasted space. Type distinctions also aid in creating portable code by ensuring consistent behaviour across platforms. Strongly typed languages require explicit declarations to avoid bugs caused by implicit type conversions during operations or function calls.

Hire a tutor

Please fill out the form and we'll find a tutor for you.

1/2
Your details
Alternatively contact us via
WhatsApp, Phone Call, or Email