Hi,
Check this program.
#include <stdio.h>
int main()
{
int x = 0xFFFFFFF0;
printf("%X\n",x );
char y = x;
printf("%X\n", y);
getchar();
}
I have FFFFFFF0 in int variable x and i am assigning it to char. Since a char can hold only 8 bits, it should have only F0. But when i try to print it, it prints the entire content as we had in int.
If i change the signed char to unsigned char it is working as per expectation. Can any one help me in understanding the underlying conversions.
If we have a signed char, will the value be stored in 2's complement ?
Check this program.
#include <stdio.h>
int main()
{
int x = 0xFFFFFFF0;
printf("%X\n",x );
char y = x;
printf("%X\n", y);
getchar();
}
I have FFFFFFF0 in int variable x and i am assigning it to char. Since a char can hold only 8 bits, it should have only F0. But when i try to print it, it prints the entire content as we had in int.
If i change the signed char to unsigned char it is working as per expectation. Can any one help me in understanding the underlying conversions.
If we have a signed char, will the value be stored in 2's complement ?
Comment