Does C sign extend constants or zero extend them?
For example:
int a = 123 & 0x3
is the 0x3 zero extend or sign extended?
Also in general, what things are zero extended in C and what are sign extended?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The C standard does not mandate whether the implementation uses 2’s complement, 1’s complement, or something else. So the representation of negative values is not mandated either.
However, in your particular case,
0x3is a positive value, so sign-extension and zero-extension are the same thing!