Describe the rule of signextension eg extend a 16bit signed

Describe the rule of sign-extension (e.g. extend a 16-bit signed integer to a 32-bit signed integer) when using two\'s complement representation for an integer.

Solution

Rule of Sign-Extension when using 2’s complement representation of an integer

Before we understand the said rule, let’s recapitulate the basics of 2’s complement of a signed integer. As we know using 2’s complement representation of an integer, we can easily perform binary arithmetic operations on integers. While 2’s complement of a positive number is the simple binary representation of the number, 2’s complement of a negative number is it’s 1’s complement (changing 1 to 0 & 0 to 1 in the binary representation of the positive number)+1. The left most bit or MSB (most significant bit) of this representation gives the sign of the integer, 1 indicating a negative integer & 0 indicating a positive integer.

For e.g.:

2’s complement of +5 (8 bit representation): 00000101 , leftmost 0 indicating positive sign

2’s complement of -5 (8 bit representation):

Step1: 1’s complement of 5 : 11111010

Step2: Adding 1 to number obtained in step 1: 11111011, leftmost 1 indicating negative sign

Now with reference to above discussion, sign-extension rule when using 2’s complement representation of an integer is to increase the number of bits in a binary number without changing the sign (positive/negative) & value of the original number. For e.g., extending an 8 bit signed integer to have 16 bits or 16 bits signed integer to have 32 bits. The method to do so is to fill the extra bits with the MSB (signed bit) of the original number, hence the name sign extension.

For e.g.:

Let’s consider the 8 bit 2’s complement representation of 50:

50 = 0 0 1 1 0 0 1 0 , the signed bit/left most bit/MSB is 0

Now after applying the sign-extension rule i.e. filling the extra bits with MSB, the 16 bit 2’s complement representation of 50:

50 = 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0

Similarly after applying the sign-extension rule, the 32 bit 2’s complement representation of 50:

50 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0

Now, let’s consider the 8 bit 2’s complement representation of -5:

-5 = 1 1 1 1 1 0 1 1 (as discussed above), the signed bit/left most bit/MSB is 1

Now after applying the sign-extension rule i.e. filling the extra bits with MSB, the 16 bit 2’s complement representation of -5:

-5 = 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1

Similarly after applying the sign-extension rule, the 32 bit 2’s complement representation of -5:

-5 = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1

Note that as discussed although the number of bits have increased from 8 to 16 to 32, the magnitude and sign of the original number remains unchanged.

 Describe the rule of sign-extension (e.g. extend a 16-bit signed integer to a 32-bit signed integer) when using two\'s complement representation for an integer

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site