简体   繁体   中英

Bit Padding (C)

I have this code: (assuming short ints are 16 bits wide, and ints are 32 bits wide)

short int x = -5;
int y;
y = x;

Does padding on the left with the sign bit to increase precision change the value of a negative number?

Does padding (sign-extension) on the left with the sign bit to increase precision change the value of a negative number?

Taking into acount @Amin Negm-Awad , when a variable is assigned from one type to another, and the value is representable in both types, like -5 as in int or short , there is no value nor precision change.

This applies if a type is int , short , char , float , etc. It also applies if integer types are 2's complement or not. The size of the type makes no difference. Endian makes no difference, The value is preserved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM