Convert Hex to Double

前端 未结 4 1715
小蘑菇
小蘑菇 2020-12-11 17:50

how do you set specific bits for a double?

For an int I\'d do something like this:

public static int Value { get { return 0xfff8; } }
4条回答
  •  猫巷女王i
    2020-12-11 17:59

    Look at the BitConverter class or go unsafe.

    Unsafe example (untested):

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

    BitConverter example:

    double d = BitConverter.Int64BitsToDouble(0xdeadbeef);
    

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

提交回复
热议问题