理解float

2020-10-21  本文已影响0人  linuxScripter

z@z-Calistoga-ICH7M-Chipset:~/zfloatNumber$ cat z.c

#include "stdio.h"

union zz {

  unsigned char ch[4];

  float f;

}z;

int main(void)

{

  z.ch[0] =  0x5a;

  z.ch[1] =  0x5a;

  z.ch[2] =  0x5a;

  z.ch[3] =  0x4a;

  printf("%lf\n", (double)z.f);

  printf("%d\n", sizeof(float) );

  z.f = 3.14;

  printf("%x %x %x %x\n", z.ch[0], z.ch[1], z.ch[2], z.ch[3]);

  return 0;

}

z@z-Calistoga-ICH7M-Chipset:~/zfloatNumber$ gcc z.c; ./a.out

3577494.500000

4

c3 f5 48 40

把0x4a换作0xca则为:

z@z-Calistoga-ICH7M-Chipset:~/zfloatNumber$ gcc z.c; ./a.out

-3577494.500000

4

c3 f5 48 40

说明,字符[3]是高位。

上一篇下一篇

猜你喜欢

热点阅读