Sign Extension
This is a very common thing done in Computer Architecture, that I got introduced to in ECE222.
Sign-extend: To increase the size of a data item by replicating the high-order sign bit of the original data item in the high-order bits of the larger, destination data item.
In Practice
To sign extend, just take the most significant bit and place them left of the word as much as possible. This is for Two’s Complement representation.
Ex: 16-bit binary representation of 2 is
00000000 00000010
, so the MSB is0
- 32-bit version is
00000000 00000000 00000000 00000010
On the other hand, the 16-bit binary representation is
1111 1111 1111 1110
, so the MSB is1
- 32-bit version is
11111111 11111111 11111111 11111110