When I compile your code using -Wall , I received complaints:
BASH> gcc -Wall left-shift.c left-shift.c: In function 'main': left-shift.c:21:12: warning: format '%X' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=] printf(" \n 1<<%i \n mul: 0x%X , val: 0x%X\n",i, mul, val); ^ left-shift.c:21:12: warning: format '%X' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int' [-Wformat=]
So I changed printf to
printf(" \n 1<<%i \n mul: 0x%lX , val: 0x%lX\n",i, mul, val);
With this change, "mul" and "val" show the same results:
1<<30 mul: 0x40000000 , val: 0x40000000 1<<31 mul: 0x80000000 , val: 0x80000000 1<<32 mul: 0x100000000 , val: 0x100000000 1<<33 mul: 0x200000000 , val: 0x200000000
System Information:
BASH> gcc --version gcc (Ubuntu 5.3.1-14ubuntu2.1) 5.3.1 20160413 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. BASH> uname -a Linux bm-pc-ubuntu 4.4.0-24-generic
source share