是否可以將浮點數從大端轉換爲小端?我從我通過UDP發送到Windows進程(little endian)的大端平臺獲得了一個值。這個值是一個浮點數,但是當我嘗試BitConverter.ToSingle時,我總是得到5.832204E-42,但它應該是36.000。使用C將大端的浮點數轉換爲小端#
我在做什麼錯?
這裏是剪斷一個代碼:
// 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;
}
你嘗試只是扭轉了陣列的第一? –
是的,其顯示只有0 :( – Termin
請告訴我們的數據。 –