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

时间:2022-12-29 21:20:26
             float floatA = 2.2f;
uint a = BitConverter.ToUInt32(BitConverter.GetBytes(floatA), );
for (int i = ; i < ;++i )
{
uint temp = 0x80000000 & (a << i);
if (temp==)
{
Console.Write("0 ");
}
else
{
Console.Write("1 ");
}
} Console.WriteLine(); double doubleA = 2.2;
ulong b = BitConverter.ToUInt64(BitConverter.GetBytes(doubleA), );
for (int i = ; i < ; ++i)
{
ulong temp = 0x8000000000000000 & (b << i);
if (temp == )
{
Console.Write("0 ");
}
else
{
Console.Write("1 ");
}
}