巧用Union

来源:互联网 发布:淘宝购物货到付款流程 编辑:程序博客网 时间:2024/05/09 00:44

#include <iostream.h>

int main()
{
 float f =0.1;
 double d = 0.1;
 union f2l{
  float f;
  unsigned long ul;
 } fl;
 
 union d2l{
  double d;
  unsigned long ull[2];
 } dl;
 fl.f = f;
 dl.d = d;
 printf("hex of float is %2X/n",f);
 printf("hex of float is %2X/n",fl.ul);
 
 
 printf("hex of double is %2X/n",d);
 printf("hex of double is %2X  %2X/n",dl.ull[1],dl.ull[0]); 

 

 

hex of float is A0000000
hex of float is 3DCCCCCD
hex of double is 9999999A
hex of double is 3FB99999  9999999A

原创粉丝点击