💡 Data Representation – Signed Number Representation
When you look at numbers like 5, -8, or 0, your brain instantly knows which are positive and which are negative.
But here’s the catch: computers don’t “see” numbers like we do. They only understand 0s and 1s, because everything inside a computer is made up of tiny electronic switches — either ON (1) or OFF (0).
So how does a computer store both positive and negative numbers using just 0s and 1s?
That’s what signed number representation is all about!
🧠 Unsigned vs Signed Numbers
Before diving in, let’s start with something simple.
- Unsigned numbers are always positive.
For example, with 4 bits, you can represent numbers from 0 to 15 (that’s 0000 to 1111 in binary). - Signed numbers, on the other hand, can be positive or negative.
That means part of those 4 bits must be used to show the sign — whether the number is + or -.
➕➖ The Sign Bit
In signed representation, the leftmost bit (also called the most significant bit or MSB) is used to indicate the sign of the number.
- 0 → means the number is positive
- 1 → means the number is negative
Example:
If we’re using 4 bits:
0101→ positive 51101→ negative number (the exact value depends on the representation method)
So basically, that first bit acts like a “+” or “–” sign in front of the number.
🧩 Types of Signed Number Representations
There are three main methods that computers use to represent signed numbers:
- Sign-Magnitude Representation
- 1’s Complement Representation
- 2’s Complement Representation
Let’s explore each one in a simple way.
⚙️ 1. Sign-Magnitude Representation
This is the easiest to understand because it works like the way we write numbers in real life.
- The first bit shows the sign (0 for +, 1 for -).
- The remaining bits show the magnitude (the size of the number).
Example (4-bit system):
| Decimal | Binary (Sign-Magnitude) |
|---|---|
| +5 | 0101 |
| -5 | 1101 |
So:
0101→ +5 (sign bit 0, magnitude 101)1101→ -5 (sign bit 1, magnitude 101)
Drawback:
There are two representations for zero → 0000 (+0) and 1000 (-0).
Computers don’t like confusion like that, so this method isn’t used much in modern systems.
⚙️ 2. 1’s Complement Representation
Here, positive numbers stay the same.
But to get the negative version of a number, you simply invert all the bits — change 0s to 1s and 1s to 0s.
Example (4-bit system):
| Decimal | Binary (1’s Complement) |
|---|---|
| +5 | 0101 |
| -5 | 1010 |
How did we get -5?
We flipped every bit of +5 (0101 → 1010).
Drawback:
Again, there are two zeros:
- +0 →
0000 - -0 →
1111
That’s confusing, so we needed something better…
⚙️ 3. 2’s Complement Representation
This is the most popular and widely used method today.
It solves the “two zeros” problem and makes calculations much simpler for the computer.
How to find the 2’s complement of a number:
- Write its positive binary form.
- Invert all bits (change 0 → 1 and 1 → 0).
- Add 1 to the result.
Example (4-bit system):
Let’s find -5.
- +5 =
0101 - Invert bits →
1010 - Add 1 →
1011
✅ So -5 = 1011 (in 2’s complement)
🧮 Range of Numbers (4-bit example)
| Representation | Range |
|---|---|
| Sign-Magnitude | -7 to +7 |
| 1’s Complement | -7 to +7 |
| 2’s Complement | -8 to +7 |
The extra negative number in 2’s complement happens because zero has only one form here.
🧠 Why 2’s Complement Is So Popular
- Only one zero (no +0 or -0 confusion)
- Easy for hardware to perform addition and subtraction
- Simplifies logic circuits in the CPU
That’s why almost every modern computer uses 2’s complement for signed integers.
🔍 Visual Diagram: Signed Number Representation
+-----------------------------+
| Signed Number System |
+-------------+---------------+
|
+------------------------+------------------------+
| | |
v v v
+------------+ +----------------+ +----------------+
| Sign- | | 1’s | | 2’s |
| Magnitude | | Complement | | Complement |
+------------+ +----------------+ +----------------+
| Sign bit + | | Flip all bits | | Flip all bits |
| magnitude | | of +ve number | | and add 1 |
| | | | | |
| Ex: +5=0101| | Ex: +5=0101 | | Ex: +5=0101 |
| -5=1101| | -5=1010 | | -5=1011 |
+------------+ +----------------+ +----------------+
💬 In Simple Words
Think of it like this:
- Sign-magnitude → Like writing +5 or -5 on paper.
- 1’s complement → Like flipping all lights from ON to OFF.
- 2’s complement → Flip all lights and then turn on one extra bulb at the end.