如何将4个字节的int转为1个字节的BYTE?

int i=0x00000001;

要取得最后一个字节的0x01?

BYTE ret;

BYTE *ptr;
ptr=(BYTE*)(&i);

ret=*ptr;   //小端内存




#####################################

以下内容为转载

x的高字节存放到x_high,把低字节x_low

int x=12345;

unsigned char x_low;

unsigned char x_high;

unsigned char *ptr;

ptr=(unsigned char*)(&x);

//小端内存

x_low = *ptr;

x_high = *(ptr+(sizeof(int)-1));

//大端内存

x_high = *ptr;

x_low = *(ptr+(sizeof(int)-1));

你可能感兴趣的:(C++)