I'm trying understand shifting and masking and I found this code from here...
https://answers.yahoo.com/question/index?qid=20120812164745AAn4i6L
When I run the program, I have to enter an input before I see "enter a digit...". The code seems ok to me so not sure why the print statement doesn't appear first. Am I missing something? I'm fairly new to C but it looks ok to me
#include <stdio.h>
int main(void) {
unsigned int hex, h1, h2, h3, h4;
printf("enter a eight-digit hex value: \n");
scanf("%x", &hex);
/* bit masking */
h1= hex & 0x000000ff;
h2= hex & 0x0000ff00;
h3= hex & 0x00ff0000;
h4= hex & 0xff000000;
/*shift bits to right as indicated */
printf("%x\n", h1);
printf("%x\n", h2);
printf("%x\n", h3);
printf("%x\n", h4);
h2 >>= 8;
h3 >>= 16;
h4 >>= 24;
/* print output */
printf("\n 0x%08x is composed of %02x %02x %02x %02x\n",
hex, h4, h3, h2, h1);
return 0;
}