How come << falls through at 16 on a 32-bit integer?

Geoffrey Rogers grogers at convex.com
Sun Apr 14 00:38:44 AEST 1991


In article <11004 at uwm.edu> markh at csd4.csd.uwm.edu (Mark William Hopkins) writes:
>* #include <stdio.h>
>* main() {
>*    unsigned long M = 34;
>*    printf("%08x\n", M << 16);
>* }

No. The problem is the %08x expects an int and you are printing a long
(unsigned long). You must also use the l flag to tell printf that the
argument is a long. Try:

	printf("%08lx\n", M << 16)


+------------------------------------+---------------------------------+
| Geoffrey C. Rogers   		     | "Whose brain did you get?"      |
| grogers at convex.com                 | "Abbie Normal!"                 |
| {sun,uunet,uiucdcs}!convex!grogers |                                 |
+------------------------------------+---------------------------------+



More information about the Comp.lang.c mailing list