我必须在我的服务中合并两个16位整数并尝试将其转换为32位浮点值,但我无法获取。最后,我弄清楚该怎么做。
Int16 val1 = 0;
Int16 val2 = 16880;
输出应为:
30
答案 0 :(得分:1)
Int16 val1 = 0;
Int16 val2 = 16880;
var byteval1 = BitConverter.GetBytes(val1);
var byteval2 = BitConverter.GetBytes(val2);
byte[] temp2 = new byte[4];
temp2[0] = byteval1[0];
temp2[1] = byteval1[1];
temp2[2] = byteval2[0];
temp2[3] = byteval2[1];
float myFloat = System.BitConverter.ToSingle(temp2, 0);