十六进制转换为Double

问题描述:

您为双

对于int我会做这样的事情:

For an int I'd do something like this:

public static int Value { get { return 0xfff8; } }



我应该怎么双怎么办?

What should I do for double?

public static double Value { get { return 0xfff8; } }



我有点担心,我可以从0xfff8一个int表示获得的隐式转换到双浮点表示。但是,我真的希望那0xfff8位模式的无论的类型。

的看 BitConverter 类或进入不安全

不安全的例子(未经测试):

Unsafe example (untested):

public unsafe double FromLong(long x)
{
  return *((double*)&x);
}



BitConverter例如:

BitConverter example:

double d = BitConverter.Int64BitsToDouble(0xdeadbeef);

http://msdn2.microsoft.com/en-us/library/system.bitconverter.int64bitstodouble