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?
kinger29
0
Light Poster
Recommended Answers
Jump to PostSign-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 …
Jump to PostC decides whether to sign extend or zero-extend when you cast an integer type based on whether it's signed or unsigned.
All 5 Replies
shrughes
19
Light Poster
kinger29
commented:
Thank you
+1
ssDimensionss
0
Newbie Poster
thoughtcoder
167
Junior Poster
ssDimensionss
0
Newbie Poster
trololo
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.