Why Learn Signed and Unsigned Numbers? Every processor instruction, memory address, and data value is stored as binary numbers—but how does hardware distinguish between positive and negative values? Understanding signed and unsigned representation is critical for embedded systems, processor design, and avoiding overflow bugs in hardware.
10 min read | Beginner Level
What You'll Learn
- Understand the difference between signed and unsigned binary numbers
- Learn two's complement representation for negative numbers
- Convert between signed/unsigned binary and decimal
- Recognize when to use signed vs unsigned in digital design
Binary Number Formats
Computer hardware recognizes two fundamental formats for interpreting binary numbers:
- Unsigned: Represents only positive values (0 and above)
- Signed: Represents both positive and negative values using two's complement notation
Unsigned Numbers
An unsigned number is a binary number that represents only magnitude (size) without a sign. It uses a fixed number of bits to represent a range of non-negative values, always including zero.
In an unsigned number system, all bits represent the magnitude of the number. For an n-bit unsigned number, the range is from 0 to 2n - 1.
Example: An 8-bit unsigned number can represent values from 0 to 255 (28 - 1 = 255).
The binary representation of decimal 10 in an 8-bit unsigned system is 00001010.
Unsigned Number Range Example (8-bit)
0000 0000 = 0
0000 0001 = 1
0000 0010 = 2
...
1111 1110 = 254
1111 1111 = 255
In unsigned representation, there is no sign bit. The leftmost bit is part of the magnitude, not a sign indicator. For example, binary 1010 represents decimal 10 in unsigned format.
Unsigned numbers are commonly used in digital systems where only positive values are needed, such as:
- Counters: Timer counts, loop iterations
- Memory addresses: RAM and ROM addressing
- Physical quantities: Distance, temperature (Kelvin), frequency
Where Are Unsigned Numbers Used? Unsigned integers are used extensively in memory addressing (where negative addresses make no sense), pixel color values (0-255 per RGB channel), and hardware counters. Most processor architectures provide separate instructions for unsigned and signed arithmetic.
Signed Numbers
A signed number is a binary number that represents both magnitude and sign (positive or negative). It uses a fixed number of bits to represent a range that includes both negative and positive values.
The most common representation for signed numbers is two's complement, which is used in virtually all modern processors.
Two's Complement Representation
In two's complement notation:
- The most significant bit (MSB) is the sign bit: 0 = positive, 1 = negative
- Positive numbers are represented normally (same as unsigned)
- Negative numbers are represented by inverting all bits and adding 1
For an n-bit signed number using two's complement, the range is from -2n-1 to 2n-1 - 1.
Example: An 8-bit signed number can represent values from -128 to +127.
Signed Number Range Example (8-bit Two's Complement)
0000 0000 = 0
0000 0001 = 1
0000 0010 = 2
...
0111 1111 = 127 (largest positive)
1000 0000 = -128 (most negative)
1000 0001 = -127
...
1111 1110 = -2
1111 1111 = -1
The two's complement representation has a useful property: adding a number and its negative always gives zero. For example, 5 + (-5) = 00000101 + 11111011 = 00000000 (ignoring carry-out).
The leftmost bit (MSB) indicates the sign: 0 for positive, 1 for negative. The remaining bits represent the magnitude in two's complement form.
Example: The binary number 11010101 in two's complement:
- MSB is 1, so the number is negative
- To find the magnitude, take two's complement: invert bits (00101010) and add 1 = 00101011 = 43
- Therefore, 11010101 = -43 in decimal
Why Two's Complement?
| Advantage | Explanation |
|---|---|
| Single zero representation | Unlike sign-magnitude, there's only one representation for zero (00000000) |
| Simple addition/subtraction | Same hardware adder works for both signed and unsigned numbers |
| Easy negation | To negate: invert all bits and add 1 |
| Hardware efficiency | No special cases or separate sign logic needed |
Where Are Signed Numbers Used? Signed integers are essential in temperature sensors (negative temperatures), financial calculations (debits/credits), coordinate systems (negative x/y positions), and arithmetic operations in processors. The ALU (Arithmetic Logic Unit) in CPUs uses two's complement for efficient signed arithmetic.
Convert Unsigned Binary to Decimal
An unsigned binary number is converted to decimal by multiplying each bit by its positional weight (power of 2) and summing the results.
Example: Convert unsigned binary 10110110 to decimal:
Bit Position: 7 6 5 4 3 2 1 0 Binary: 1 0 1 1 0 1 1 0 Weight (2^n): 128 64 32 16 8 4 2 1 Contribution: 128 0 32 16 0 4 2 0
Calculation:
128 + 0 + 32 + 16 + 0 + 4 + 2 + 0 = 182
Therefore, unsigned binary 10110110 = decimal 182
Quick Check Q: What is the decimal value of unsigned binary 11111111?
Show Answer
A: 255
Explanation: All 8 bits are set, so it's the maximum value for an 8-bit unsigned number: 128+64+32+16+8+4+2+1 = 255, or simply 28 - 1 = 255
Convert Signed Binary to Decimal (Two's Complement)
To convert a two's complement signed binary number to decimal:
- Check the MSB (sign bit)
- If MSB = 0, the number is positive: convert as unsigned
- If MSB = 1, the number is negative: find two's complement, convert to decimal, add negative sign
Method for Negative Numbers:
- Invert all bits (0 → 1, 1 → 0)
- Add 1 to the result
- Convert the result to decimal
- Add a negative sign
Example: Convert signed binary 11011010 to decimal:
- MSB is 1, so the number is negative
- Invert all bits: 11011010 → 00100101
- Add 1: 00100101 + 1 = 00100110
- Convert to decimal: 00100110 = 32 + 4 + 2 = 38
- Add negative sign: -38
Therefore, signed binary 11011010 = decimal -38
Quick check for two's complement: The most negative value for n bits is always -2n-1. For 8 bits: 10000000 = -128.
Alternative Method: Sign-Magnitude (Less Common)
Some older systems used sign-magnitude representation where:
- The MSB is the sign bit (0 = positive, 1 = negative)
- The remaining bits represent the magnitude directly
Example: In sign-magnitude, 10101110 would be:
- Sign bit = 1 (negative)
- Magnitude = 0101110 = 46
- Result: -46
Sign-magnitude has two representations for zero (00000000 and 10000000) and requires more complex hardware for arithmetic. This is why two's complement is universally preferred in modern digital systems.
Signed vs. Unsigned: When to Use Each
| Use Case | Signed | Unsigned |
|---|---|---|
| Temperature (Celsius) | ✓ | |
| Memory Addresses | ✓ | |
| Pixel RGB Values (0-255) | ✓ | |
| Bank Balance (debit/credit) | ✓ | |
| Counter (always increasing) | ✓ | |
| Position Coordinates | ✓ | |
| Age in Years | ✓ |
Common Beginner Mistakes
Mistake #1: Treating signed numbers as unsigned (or vice versa)
Wrong: Interpreting binary 11111111 as 255 when it's actually -1 in signed representation
Right: Check the context: 11111111 = 255 (unsigned) or -1 (signed two's complement)
Why? The same bit pattern has different meanings depending on the interpretation. Hardware needs to know which arithmetic mode to use.
Mistake #2: Forgetting to add 1 after inverting bits in two's complement
Wrong: To negate 00000101, just invert to get 11111010
Right: Invert to 11111010, then add 1 to get 11111011 = -5
Why? Two's complement requires both steps: invert AND add 1.
Mistake #3: Assuming the range is symmetric for signed numbers
Wrong: Thinking 8-bit signed ranges from -127 to +127
Right: 8-bit signed ranges from -128 to +127 (one more negative value)
Why? Two's complement has an asymmetric range because there's only one representation for zero.
Mistake #4: Using sign-magnitude conversion for two's complement
Wrong: Converting 10101110 as sign bit (1) + magnitude (0101110 = 46) = -46
Right: Use two's complement: invert + add 1, then negate
Why? Modern systems use two's complement, not sign-magnitude. Always verify which representation is being used.
Summary
In this tutorial, you learned:
- Unsigned numbers represent only non-negative values from 0 to 2n-1
- Signed numbers use two's complement to represent both positive and negative values
- Two's complement range for n bits: -2n-1 to 2n-1-1 (asymmetric)
- To negate a two's complement number: invert all bits and add 1
- The MSB is the sign bit in two's complement (0 = positive, 1 = negative)
- The same bit pattern has different meanings in signed vs unsigned interpretation
- Two's complement is universally used in modern processors due to hardware efficiency