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);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM