试试这个:
int i = 2; float f = (float)i; printf("%#08X", *( (int*) &f ));
[编辑]
@Corey:
让我们从里到外解析它:
& f = address of f = say address 0x5ca1ab1e (int*) &f = interpret the address 0x5ca1ab1e as integer pointer * ((int*)&f) = get the integer at address 0x5ca1ab1e
以下更简洁,但很难记住C语言的运算符关联性和运算符优先级(我更喜欢一些添加的括号和空格提供的额外清晰度):
printf("%#08X", *(int*)&f);