Negative Numbers and Binary
Have you ever wondered how a computer stores a number like $-12$ or why a game score can go below zero? 🤔 students, this lesson explains how computers represent negative numbers using binary. This is a key part of System Fundamentals because computers only store data as bits, yet they still need to handle positives, negatives, and arithmetic correctly.
What you will learn
By the end of this lesson, you should be able to:
- Explain why binary is the language computers use to store data.
- Describe how positive and negative numbers are represented in binary.
- Use two’s complement to convert between decimal and binary negative numbers.
- Explain why two’s complement is widely used in computer systems.
- Connect number representation to memory size, overflow, and computer performance.
Why computers need a special way to store negative numbers
A computer does not store numbers the same way humans write them on paper. It stores everything as patterns of bits, where each bit is either $0$ or $1$. If a number is positive, binary is fairly straightforward. For example, the decimal number $5$ is $101_2$.
But negative numbers create a problem. If a computer only used normal binary, it would need a clear rule for showing the sign, just like a minus sign in decimal. Computers cannot store a “minus sign” as text in the same simple way. Instead, they use binary patterns that include a way to show whether a number is positive or negative.
One early method was sign-magnitude. In sign-magnitude, the first bit shows the sign: $0$ for positive and $1$ for negative. The rest of the bits show the value. For example, using $8$ bits, $+5$ could be $00000101_2$ and $-5$ could be $10000101_2$.
This seems simple, but it causes problems. There are two different representations of zero: $00000000_2$ and $10000000_2$. Also, arithmetic becomes harder for the processor. Because of this, modern computers mostly use two’s complement instead. ✅
Two’s complement: the main method used today
Two’s complement is the standard way computers represent signed integers. In this system, the leftmost bit, called the most significant bit or MSB, acts as the sign indicator in a way that is built into the number pattern itself.
For an $n$-bit two’s complement number:
- If the MSB is $0$, the number is non-negative.
- If the MSB is $1$, the number is negative.
The range of values is:
$$-2^{n-1} \text{ to } 2^{n-1}-1$$
For $8$ bits, that means:
$$-128 \text{ to } 127$$
This range is not symmetric because one extra value is used for zero and positive numbers. This is a very important idea in system fundamentals because memory size determines the range of values a computer can store.
How to find the two’s complement of a negative number
To represent a negative decimal number in two’s complement, follow these steps:
- Write the positive version in binary.
- Use the required number of bits.
- Invert every bit.
- Add $1$.
Example: represent $-5$ in $8$ bits.
First, write $+5$:
$$00000101_2$$
Invert the bits:
$$11111010_2$$
Add $1$:
$$11111011_2$$
So $-5$ in $8$-bit two’s complement is:
$$11111011_2$$
You can check this by reversing the process. If you start with $11111011_2$, invert it to get $00000100_2$, then add $1$ to get $00000101_2$, which is $5$. Since the original number begins with $1$, it is negative, so the result is $-5$.
Reading two’s complement numbers
To read a two’s complement binary number, first look at the leftmost bit.
Example 1: $00101100_2$
- The MSB is $0$, so the number is positive.
- Convert it normally: $00101100_2 = 44_{10}$.
Example 2: $11110110_2$
- The MSB is $1$, so the number is negative.
- To find the value, invert the bits: $00001001_2$
- Add $1$: $00001010_2 = 10_{10}$
- Therefore, the original number is $-10_{10}$.
This method works because two’s complement is designed so that addition and subtraction can be done with the same hardware for both positive and negative integers. That is one reason it is so efficient in computers. ⚙️
Binary addition with negative numbers
One major advantage of two’s complement is that the computer can use the same binary addition circuit for all integers.
Let’s add $7$ and $-3$ using $8$ bits.
$$7 = 00000111_2$$
$$-3 = 11111101_2$$
Now add them:
$$00000111_2 + 11111101_2 = 1\,00000100_2$$
In $8$ bits, the extra carry beyond the $8$th bit is ignored, so the result is:
$$00000100_2$$
That equals $4_{10}$, and indeed:
$$7 + (-3) = 4$$
This is a powerful idea. The computer does not need one method for positive addition and a different method for negative addition. It just adds bits and ignores the carry beyond the bit width.
Overflow
Overflow happens when the result is too large or too small to fit in the available number of bits.
For example, in $8$-bit two’s complement, the largest number is $127$. If you add $1$ to $127$, the computer cannot store $128$ in $8$ bits.
$$01111111_2 + 00000001_2 = 10000000_2$$
But $10000000_2$ in $8$-bit two’s complement means $-128$, not $128$. This shows overflow: the stored result is incorrect because it moved outside the valid range.
Overflow matters in real systems. A calculator, a game score, or a sensor reading may give wrong results if the number is too large for the bit size. This links number representation to reliability and system design.
Why two’s complement is better than sign-magnitude
Two’s complement is preferred because it has several advantages:
- Only one representation of zero.
- Addition and subtraction use the same hardware logic.
- Negative values can be handled efficiently.
- The bit pattern order matches numeric order when interpreted correctly.
For example, with $8$-bit two’s complement, the sequence around zero is:
$$11111111_2 = -1$$
$$00000000_2 = 0$$
$$00000001_2 = 1$$
This makes computation simpler for the CPU. Since processors perform billions of arithmetic operations, even small improvements in simplicity and speed matter a lot.
Real-world connections in system fundamentals
Negative numbers and binary connect to several parts of System Fundamentals:
- System architecture and operation: The CPU uses arithmetic logic units to perform binary arithmetic, including negative numbers.
- Data representation: Signed integers are stored using two’s complement.
- Computer performance: Efficient number handling improves processing speed and reduces circuit complexity.
- Memory management: The number of bits available affects the range of values.
- Ethics and social impact: Incorrect number representation can affect systems in finance, healthcare, transport, and engineering where accurate data is essential.
Example: A temperature sensor may read below zero. If the system stores signed values incorrectly, the display could show a wrong temperature. In a hospital, that kind of error could cause serious problems. Because of this, accurate data representation is not just a technical detail; it has real consequences.
Common mistakes to avoid
students, here are some errors students often make:
- Forgetting that the MSB determines whether the value is negative in two’s complement.
- Inverting bits but forgetting to add $1$ when finding a negative value.
- Confusing sign-magnitude with two’s complement.
- Assuming the range is the same on both sides of zero.
- Ignoring overflow when the result does not fit in the available bits.
A good habit is to always ask: How many bits are being used? What is the allowed range? Is the number signed or unsigned?
Conclusion
Negative numbers in binary are a major example of how computers turn abstract ideas into exact bit patterns. The most important system used today is two’s complement because it makes arithmetic efficient and avoids many problems found in older methods. Understanding this topic helps you explain how computers store data, process numbers, and avoid errors caused by limited memory size. In IB Computer Science HL, this knowledge supports your understanding of data representation, system operation, and the practical limits of computing.
Study Notes
- Computers store all data as bits, but numbers can be positive or negative.
- Two’s complement is the standard method for representing signed integers.
- In $n$ bits, the two’s complement range is $$-2^{n-1} \text{ to } 2^{n-1}-1$$
- If the MSB is $0$, the number is non-negative; if it is $1$, the number is negative.
- To find a negative number in two’s complement: write the positive binary form, invert the bits, then add $1$.
- Two’s complement has only one zero and makes binary arithmetic simpler.
- Overflow happens when a result cannot fit in the available number of bits.
- Number representation connects directly to system architecture, performance, and reliability.
