#include <stdio.h> //pass
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
//x的最低有效字节设置成全1,其他字节都保持不变
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 | 0xFF; // 只保留地位一个字节,高位字节被清0
valp=(byte_pointer)y;
show_bytes(valp,4); //长度应该是4
}
void main()
{
int x=0x87654321;
show_last_two_bytes(&x);
}
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
//x的最低有效字节设置成全1,其他字节都保持不变
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 | 0xFF; // 只保留地位一个字节,高位字节被清0
valp=(byte_pointer)y;
show_bytes(valp,4); //长度应该是4
}
void main()
{
int x=0x87654321;
show_last_two_bytes(&x);
}