0
\$\begingroup\$

Sign-extension works this way: You pad with zeros for a positive number and pad with ones for a negative number, because of two's complement, and left or right depends on endianness.

Did I understand it correctly? Do I need to know more if I'm looking to understand it as it is described e.g. in Pattersson (Comp. Organization)?

\$\endgroup\$
5
  • 4
    \$\begingroup\$ Endianness operates at byte-level, not bit-level. \$\endgroup\$ Commented Aug 17, 2016 at 6:49
  • \$\begingroup\$ Which page in his book are you referring to? (I have the 4th edition here.) I don't think you understand it correctly. \$\endgroup\$
    – jonk
    Commented Aug 17, 2016 at 7:43
  • \$\begingroup\$ Apart from the 'left or right depends on endianness' I think yopu got it right. Forget about endianess, focus on the the value as string of bits. \$\endgroup\$ Commented Aug 17, 2016 at 7:50
  • \$\begingroup\$ @IgnacioVazquez-Abrams Endianness applies to the unit of address resolution, which is usually a byte but may be anything, including single bits. \$\endgroup\$ Commented Aug 17, 2016 at 8:29
  • \$\begingroup\$ @DmitryGrigoryev .. but only on the external interface, not within a processor. \$\endgroup\$
    – pjc50
    Commented Aug 17, 2016 at 9:55

2 Answers 2

4
\$\begingroup\$

Sign extension is a block that takes in your input data and append bits to it based on the MSB(most significant bit) value to maintain sign integrity. It has nothing to do with endianness. Endianness is related to how data is stored in memory and varies from one architecture to another. Also sign extension usually appends bits to the left of the input data.

Link explaining endianness

\$\endgroup\$
2
\$\begingroup\$

Sign extension has nothing to do with endianess. The reason you perform sign extension is usually to fit an otherwise smaller bit-size into the required size , to maintain sign etc.

The concept behind sign extension is very simple, any twos-complement representation can be thought of having an infinite number of insignificant digits in the front after the actual MSB. For a positive number leading zeros are insignificant, ie having any number of them does not change the value of what you are trying to store . In the same way leading 1s are insignificant for a negative number stored using twos complement. Try it out yourself.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.