| | |
Sign extend 16 bit to 32 bit
Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
![]() |
•
•
Join Date: Mar 2008
Posts: 31
Reputation:
Solved Threads: 1
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?
•
•
Join Date: Oct 2008
Posts: 43
Reputation:
Solved Threads: 4
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.
This means that if your 16 bits represent a signed integer, your 32-bit value will represent the same integer.
When you write
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.
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.
•
•
Join Date: May 2008
Posts: 19
Reputation:
Solved Threads: 0
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
![]() |
Similar Threads
- Computer Architecture Reference (Computer Science)
Other Threads in the Computer Science Forum
- Previous Thread: Simple Reduction from Vertex Cover to Vertex Guard Cover
- Next Thread: Please help me!!!
| Thread Tools | Search this Thread |
Tag cloud for Computer Science
ai algorithm algorithms amazon assignment assignmenthelp assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business codebreaker compiler computerscience computertrackingsoftware connect conversion csc data dataanalysis dataintepretation development dfa dissertation dissertations dissertationtopic ebook employment energy extensions floatingpoint foreclosure foreclosuresoftware gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet iphone ipod jobs laser laws linkbait lsmeans mainframes marketing mining mobileapplication msaccess nano netbeans networking news os p2p parser piracy piratebay principles programming rasterizer research sam-being-cute sas science security simulation software spying sql stephenfry study supercomputer supercomputing sweden technology textfield tree turing uk virus warehouse ww2





