《深入理解计算机系统》(第二版)第二章中的一练习题2

#include <stdio.h>                             
#include
<stdlib.h>
#include
<malloc.h>
#include
<math.h>
#include
<string.h>
typedef unsigned
char *byte_pointer;
void show_bytes(byte_pointer start,int len){
int i;
for(i=len-1;i>=0;i--)
printf(
"%.2x ",start[i]);
printf(
"\n");
}
void show_last_two_bytes(int *y){
byte_pointer valp
=(byte_pointer)y;
show_bytes(valp,
4); //长度应该是4
*y=*y & 0xFFFF; //只保留地位二个字节,高位字节被清0
valp=(byte_pointer)y;
show_bytes(valp,
4); //长度应该是4
}
void main()
{
int x=0x87654321;
show_last_two_bytes(
&x);
}

原文地址:https://www.cnblogs.com/zzw818/p/2114701.html