C# float与UInt16互转

//float拆分成两个UInt16
public static UInt16 FloatToTwoUInt16(float f)
{
     byte[] bs = BitConvert.GetBytes();
     
     UInt16 low = BitConverter.ToUInt16(bs, 0);
     UInt16 high = BitConvert.ToUInt16(bs, 2);

     return new UInt16[]{low, high};
  }

//UInt16转float
public static float TwoUInt16ToFloat(UInt16 high, UInt16 low)
{
  Int32 sum = (high << 16)+(low & 0xFFFF);
  byte[] bs = BitConverter.GetBytes(sum);
  return BitConverter.ToSingle(bs, 0);
}

 

posted @ 2018-11-27 14:03  梦醒江南·Infinite  阅读(3641)  评论(0编辑  收藏  举报