int main(void){
//Start with the 32-bit number 0x476F6F64
int num = 0x476F6F64;
int i;
char word[5];
//puts each set of 8 bits into char variables
for(i=3; i >=0; --i){
//picks out the 8 bits in each of the four bytes
word[3-i] = ((char*)&num)[i];
}
word[4] = '\0';
//print out the chars (starting with the one corresponding to the highest-order byte,
//and going in order down to the lowest-order byte)
printf("%s\n", word);
return 0;
}
Start with the 32-bit number 0x476F6F64
? Write code that:
– picks out the 8 bits in each of the four bytes
– puts each set of 8 bits into char variables
– print out the chars (starting with the one corresponding to the highest-order byte,
and going in order down to the lowest-order byte)