943,648 Members | Top Members by Rank

Ad:
Oct 19th, 2008
0

Sign extend 16 bit to 32 bit

Expand Post »
I am trying to write a program that either zero extends or sign extends a 16 bit input to a 32 bit output, what exactly is meant by sign extending a number? I believe zero extending would be adding 16 0s in the 16 Most Significant bits, Is sign extending just keeping the most significant bit as the sign?
Similar Threads
Reputation Points: 11
Solved Threads: 2
Light Poster
kinger29 is offline Offline
35 posts
since Mar 2008
Oct 19th, 2008
1

Re: Sign extend 16 bit to 32 bit

Sign-extending means the value of the most significant bit of the 16-bit integer (the sign bit, for signed 16-bit integers) is used to fill the 16 higher bits.

0abcdefghijklmno => 00000000000000000abcdefghijklmno
1abcdefghijklmno => 11111111111111111abcdefghijklmno

This means that if your 16 bits represent a signed integer, your 32-bit value will represent the same integer.

When you write

int16_t x = -5;
int32_t y = x;

the value gets cast up to a 32-bit signed integer using the sign extension described above. If zero extension were used instead, y would be assigned the value 65531, instead of -5.
Reputation Points: 29
Solved Threads: 4
Light Poster
shrughes is offline Offline
44 posts
since Oct 2008
Apr 25th, 2009
0

Re: Sign extend 16 bit to 32 bit

Hi any ideas on how to do this using C?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ssDimensionss is offline Offline
21 posts
since May 2008
Apr 25th, 2009
0

Re: Sign extend 16 bit to 32 bit

C decides whether to sign extend or zero-extend when you cast an integer type based on whether it's signed or unsigned.
Reputation Points: 231
Solved Threads: 12
Junior Poster
thoughtcoder is offline Offline
139 posts
since Mar 2009
Apr 26th, 2009
0

Re: Sign extend 16 bit to 32 bit

well the thing is im writing a code to take a hexadecimal input which is a 32 bit instruction. The last 16bits of this instruction is a constant which i have to add to another value. But apparently i can't add it because its 16bits long and im adding to 32 bit register value. Just wondering if there's a way to make this 16bits long into 32 bits long ? Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ssDimensionss is offline Offline
21 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Simple Reduction from Vertex Cover to Vertex Guard Cover
Next Thread in Computer Science Forum Timeline: Please help me!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC