打印出C# 中float ,double 在内存中的存放形式

 1             float floatA = 2.2f;
 2             uint a = BitConverter.ToUInt32(BitConverter.GetBytes(floatA), 0);
 3             for (int i = 0; i < 32;++i )
 4             {
 5                 uint temp = 0x80000000 & (a << i);
 6                 if (temp==0)
 7                 {
 8                     Console.Write("0 ");
 9                 }
10                 else
11                 {
12                     Console.Write("1 ");
13                 }
14             }
15 
16             Console.WriteLine();
17 
18             double doubleA = 2.2;
19             ulong b = BitConverter.ToUInt64(BitConverter.GetBytes(doubleA), 0);
20             for (int i = 0; i < 64; ++i)
21             {
22                 ulong temp = 0x8000000000000000 & (b << i);
23                 if (temp == 0)
24                 {
25                     Console.Write("0 ");
26                 }
27                 else
28                 {
29                     Console.Write("1 ");
30                 }
31             }

 

posted on 2015-02-10 17:25  siszqsqx  阅读(1072)  评论(0编辑  收藏  举报

导航