My code is:
#include <stdio.h> #include <stdint.h> int main(void) { uint8_t x8 = 0xFF; uint16_t x16; uint32_t x32, x24; uint64_t x64, x56, x48, x40; x16 = x8 <<8; x24 = x8 <<16; x32 = x8 <<24; x40 = x8 <<32; x48 = x8 <<40; x56 = x8 <<48; x64 = x8 <<56; printf("\n"); printf("x8 = 0x%016x\n", x8); printf("x16 = 0x%016x\n", x16); printf("x24 = 0x%016x\n", x24); printf("x32 = 0x%016x\n", x32); printf("x40 = 0x%016x\n", x40); printf("x48 = 0x%016x\n", x48); printf("x56 = 0x%016x\n", x56); printf("x64 = 0x%016x\n", x64); return 0; } Here is what is printed:
x8 = 0x00000000000000ff x16 = 0x000000000000ff00 x24 = 0x0000000000ff0000 x32 = 0x00000000ff000000 x40 = 0x0000000000000000 x48 = 0x0000000000000000 x56 = 0x0000000000000000 x64 = 0x0000000000000000 Why are values larger than 32 bits not printed out, despite the fact that variables are 64-bit?
EDITED:
Thank you @Mark Shevchenko and @ Vladimir Martyanov !!!
The working code is:
#include <stdio.h> #include <stdint.h> int main(void) { uint8_t x8 = 0xFF; uint16_t x16; uint32_t x32, x24; uint64_t x64, x56, x48, x40; x16 = x8 <<8; x24 = x8 <<16; x32 = x8 <<24; x40 = (uint64_t)x8 <<32; x48 = (uint64_t)x8 <<40; x56 = (uint64_t)x8 <<48; x64 = (uint64_t)x8 <<56; printf("\n"); printf("x8 = 0x%016llX\n", x8); printf("x16 = 0x%016llX\n", x16); printf("x24 = 0x%016llX\n", x24); printf("x32 = 0x%016llX\n", x32); printf("x40 = 0x%016llX\n", x40); printf("x48 = 0x%016llX\n", x48); printf("x56 = 0x%016llX\n", x56); printf("x64 = 0x%016llX\n", x64); return 0; }