why is the output fffffffa rather than 0000000a for this code
char c=0Xaa; int b=(int)c; b=b>>4; printf("%x",b);
what i thought was char c=OXaa will be aa and when it is typecasted to int it changes to 000000aa.
can anyone tell me what is happening when the char is being typecasted to integer..
char
may lead to undefined behavior. Don't do that, but always assign'a'
type constants to plainchar
. To have an hexadecimal value in there you may use'\xaa'
as in your example, but there are more chances that the compiler will tell you when you exceed the bounds. – Jens Gustedt