|
|
Back to dictionarySign extension is useful when you're attempting to perform functions with two binary numbers that don't have the same number of digits. For example, when you're trying to add these two numbers:
01010101
1100
Adding these two numbers can be problematic. The first is positive 85, and the second is negative 4. But to add these and get a result we can use, they must be the same size (have the same digits).
To sign extend a number, we take the smaller number and pad it with 0s if it is positive, and 1s if it is negative. The problem above would now look like this after being sign extended:
01010101
11111100
We're now ready to add. The sum is:
01010001
There is a 1 that is carried over to the 9th bit, which, as intended, is lost. 01010001 is 81 in decimal, which is what we expect if we were to add 85 and -4.
Find more about sign extension in these tutorials:
|
|