#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <math.h> #include <string.h> //除了x的最低有效字节外,其他的位都取补 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 ^ 0xFFFFFF00; //只保留地位一个字节,其他的位都取补 valp=(byte_pointer)y; show_bytes(valp,4); //长度应该是4 } void main() { int x=0x87654321; show_last_two_bytes(&x); }