#include <iostream>
using namespace std;
typedef unsigned char *byte_pointer;
void show_bytes(byte_pointer start, size_t len){
size_t i;
for (i=0; i<len; i++) {
printf("%.1x",start[i]);
}
printf("\n");
}
int main(int argc, const char * argv[]) {
short sx = -12345;
unsigned uy = sx;
cout<<hex<<sx<<endl;
cout<<hex<<uy<<endl;
printf("uy = %u :\t",uy);
show_bytes((byte_pointer)&uy, sizeof(unsigned));
}
/*
result:
cfc7
ffffcfc7
uy = 4294954951 : c7cfffff //little endian
*/
[CSAPP]有符号到无符号的转化
最新推荐文章于 2023-02-17 22:22:31 发布