How does a computer store positive and negative whole numbers and very large or very small real numbers in binary?
Representing positive and negative integers using two's complement, and representing real numbers using floating-point with a mantissa and exponent.
An SQA Higher Computing Science answer on representing numbers in binary, covering positive and negative integers using two's complement and real numbers using floating-point representation with a mantissa and exponent.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this key area is asking
The SQA wants you to know how a computer represents numbers in binary: positive and negative integers using two's complement, and real numbers using floating-point with a mantissa and an exponent. You should be able to convert a small value to two's complement and explain the floating-point trade-off.
Why binary, and why two's complement
A computer's memory holds only two states, so all numbers are stored in binary (base 2). Positive whole numbers are straightforward binary. The challenge is negative numbers, and the standard solution is two's complement.
Two's complement is used because it lets the processor subtract by adding the negative: the same adder circuit handles both addition and subtraction, and there is only one representation of zero. This is simpler and cheaper in hardware than the alternatives.
Working in two's complement
In bits, two's complement represents values from to . In 8 bits that is to .
For example ; inverting gives ; adding 1 gives . The leading 1 confirms it is negative.
Floating-point representation of real numbers
Whole numbers are not enough: programs need real numbers such as 3.14, and very large or very small magnitudes. These use floating-point representation, the binary version of scientific notation.
This is why it is called floating-point: the same bits can represent a tiny fraction or a huge number by changing the exponent, just as and share a format in decimal.
The precision versus range trade-off
The total number of bits for a floating-point number is fixed, and it is split between the mantissa and the exponent.
So a system that needs to store extremely large and small numbers favours the exponent (range); a system that needs many accurate significant figures favours the mantissa (precision). Designers choose the split for the job.
Examples in context
These representations underpin real computing. Two's complement is the integer format in virtually every processor, which is why an 8-bit signed value wraps from to - a real cause of bugs when a counter overflows. Floating-point (the IEEE 754 standard) is how spreadsheets, games and scientific software store decimals, and the precision limit explains why does not give exactly in many languages: 0.1 has no exact finite binary mantissa. Understanding range versus precision explains why scientific code sometimes uses "double precision" (more bits) to reduce rounding error.
Try this
Q1. State the two steps used to negate a number in two's complement. [2 marks]
- Cue. Invert all the bits, then add 1.
Q2. State which part of a floating-point number determines its precision. [1 mark]
- Cue. The mantissa.
Q3. For a fixed number of bits, state what increasing the exponent bits does. [1 mark]
- Cue. It increases the range (at the cost of precision).
Exam-style practice questions
Practice questions written in the style of SQA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
SQA Higher (style)3 marksUsing two's complement in 8 bits, show how the denary value -20 is represented. Show your working.Show worked answer β
Start from positive 20, then negate using two's complement (invert the bits and add 1).
Step 1, write +20 in 8 bits: , so .
Step 2, invert every bit: .
Step 3, add 1: .
So in 8-bit two's complement. The leading bit is 1, confirming a negative value.
Markers reward the correct positive binary for 20, inverting the bits, adding 1, and the final answer 1110 1100 with the sign bit set.
SQA Higher (style)4 marksExplain how a real number is stored in floating-point representation, and describe the trade-off between using more bits for the mantissa and more bits for the exponent.Show worked answer β
A real number is stored in floating-point as two parts: a mantissa, which holds the significant digits of the number, and an exponent, which says where the binary point goes (the power of 2 to scale the mantissa by). Together they represent the number as mantissa multiplied by a base raised to the exponent, much like scientific notation.
The trade-off is for a fixed total number of bits: giving more bits to the mantissa increases precision (more significant figures, so the number is stored more accurately), while giving more bits to the exponent increases range (the largest and smallest magnitudes that can be stored). Because the total is fixed, gaining range costs precision and gaining precision costs range.
Markers reward identifying the mantissa as the significant digits and the exponent as the scaling power, and the precision (mantissa) versus range (exponent) trade-off for a fixed number of bits.
Related dot points
- Representing characters using ASCII, extended ASCII and Unicode, and the principle that program instructions and all real-world data are ultimately stored as binary.
An SQA Higher Computing Science answer on representing text and instructions in binary, covering ASCII, extended ASCII and Unicode character sets and the principle that all data and instructions are stored as binary.
- The structure of a computer: the processor (ALU, control unit and registers), the buses (data and address) used to read from and write to memory, and the difference between an interpreter and a compiler.
An SQA Higher Computing Science answer on computer structure, covering the processor (ALU, control unit and registers), the data and address buses used to access memory, and the difference between an interpreter and a compiler.
- The environmental impact of computer systems: their energy consumption, ways to reduce that impact, and the environmental considerations of intelligent systems.
An SQA Higher Computing Science answer on the environmental impact of computer systems, covering their energy consumption, practical ways to reduce that impact, and the environmental considerations raised by intelligent systems.
- Data types and structures: variables of simple types, 1-D arrays, records, and parallel arrays or arrays of records, with string operations.
An SQA Higher Computing Science answer on data types and structures, covering simple variable types, 1-D arrays, records, parallel arrays and arrays of records, plus string operations such as concatenation.
Sources & how we know this
- SQA Higher Computing Science Course Specification (C816 76) β SQA (2023)