是否可以将浮点数从大端转换为小端?我有一个来自大端平台的值,我通过UDP将其发送到 Windows 进程(小端)。这个值是一个浮点数,但是当我尝试 BitConverter.ToSingle 时,我总是得到 5.832204E-42,但它应该是 36.000。
我究竟做错了什么?
这是一段代码:
// Receive thread
private void ReceiveData()
{
int count = 0;
IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse("10.0.2.213"), port);
client = new UdpClient(remoteIP);
while (true)
{
try
{
IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.Receive(ref anyIP);
float x = BitConverter.ToSingle(data, 0);
float y = BitConverter.ToSingle(data, 4);
float z = BitConverter.ToSingle(data, 8);
float alpha = BitConverter.ToSingle (data, 12);
float theta = BitConverter.ToSingle (data, 16);
float phi = BitConverter.ToSingle (data, 20);
print(">> " + x.ToString() + ", "+ y.ToString() + ", "+ z.ToString() + ", " +
alpha.ToString() + ", "+ theta.ToString() + ", "+ phi.ToString());
// Latest UDP packet
lastReceivedUDPPacket=x.ToString()+" Packet#: "+count.ToString();
count = count+1;
}