When the negative numbers are encoded using two’s complement encoding, it has similar trait as positive numbers. This property makes it possible to reuse the same hardware between positive and negative numbers. Hence the two’s complement makes sense for hardware design perspective.
Background
What is the 8-bit binary representation of the number +3? Well, it’s simple 00000011. and what is the 8-bit binary representation of the number -3? We know that the negative numbers use the MSB for sign bit, so intuitively one might guess that -3 is represented as 10000011 but that’s not correct.
Computer systems represent the negative numbers in the 2’s complement format. That means -3 is represented as 11111101. Why did they choose 2’s complement instead of simple 1’s complement? In this post, we will discuss why this choice was made.
Number format choice
Let us take a smaller example with 4-bit numbers. unsigned 4-bit number can hold values from 0 to 15. While signed 5-bit number uses MSB for encoding and remaining bits represent the magnitude of the number. There are two options:
1’s complement format - Magnitude for the positive and negative numbers are same. MSB bit describes the sign. (+3 is 00000011 and -3 is 10000011)
2’s complement format - To get a negative number, we invert all the bits from positive number and add 1 to it. (+3 is 00000011 and -3 is 11111101)
Following diagram describes how the encoding for 1’s complement and 2’s complement format looks like for 4-bit Numbers.
Don't Miss an Update!
Helping you navigate the Embedded Systems career with ease! Technical posts, newsletters, special offers, and more.