#include <stdio.h>
//A byte pointer refers to a sequence of bytes
typedef unsigned char * byte_pointer;
//The input is a byte pointer and a byte number
void show_bytes(byte_pointer start, size_t len) {
size_t i;
for (i = 0; i < len; i++) {
//A storage unit holds one byte
printf("%.2x ", start[i]);
//Output in hexadecimal format with at least two digits
}
printf("\n");
}
//show_short
void show_short(short x) {
show_bytes((byte_pointer)&x, sizeof(short));
}
//show_long
void show_long(long x) {
show_bytes((byte_pointer)&x, sizeof(long));
}
//show_double
void show_double(double x) {
show_bytes((byte_pointer)&x, sizeof(double));
}
void show_pointer(void *x) {
show_bytes((byte_pointer)&x, sizeof(void *));
}
void test_show_bytes(int val) {
//Prints byte representations of the three target types
int ival = val;
short stval = (short)ival;
long lval = (long)ival;
double dval = (double)ival;
show_short(stval);
show_long(lval);
show_double(dval);
}
int main() {
int test = 328;
test_show_bytes(test);
return 0;
}
win64 中long占4个字节
linux64 中long占8个字节