intBitsToFloat method in Java VS C#?

前端 未结 3 420
猫巷女王i
猫巷女王i 2021-01-26 16:34

I\'m getting the wrong number when converting bits to float in C#.

Let\'s use this bit number= 1065324597

In Java, if I want to co

3条回答
  •  温柔的废话
    2021-01-26 17:18

    Just try this...

    var myBytes = BitConverter.GetBytes(1065324597);
    var mySingle = BitConverter.ToSingle(myBytes,0);
    

    The BitConverter.GetBytes converts your integer into a four byte array. Then BitConverter.ToSingle converts your array into a float(single).

提交回复
热议问题