[英]Extract float32 from TArray<uint8>
Unreal Engine (C++) 虚幻引擎(C ++)
Hi, I have a TArray of Bytes from TCP connection. 嗨,我有一个来自TCP连接的字节数组。 I have 58 Bytes of header and 12 x 4 Bytes of Float32.
我有58字节的标头和12 x 4字节的Float32。 I need to extract the 12 float32 numbers from my Array Bytes, I have tried this code for extracting the first number but the result is wrong every time:
我需要从数组字节中提取12个float32数字,我尝试使用此代码提取第一个数字,但每次结果都是错误的:
float ReceivedUE4float32;
ReceivedUE4float32 = float(ReceivedData[58]); //58 index of first float32
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Dato intdex 58 ~> %f"), ReceivedUE4float32));
Can someone help me? 有人能帮我吗?
Socket: https://github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/index.md 套接字: https : //github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/index.md
Transform (12x4 Bytes): https://github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/transform.md 转换(12x4字节): https : //github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/transform.md
float(ReceivedData[58])
will dereference the 58th byte from ReceivedData
and create a float from that value, which is not what you want. float(ReceivedData[58])
将从ReceivedData
解引用第58个字节,并根据该值创建一个浮点数,这不是您想要的。
You can use reinterpret_cast
to read the data: 您可以使用
reinterpret_cast
读取数据:
float value = *(reinterpret_cast<float*>(ReceivedData + 58));
You did not mention which platforms you are targeting, but keep in mind this pays no attention to endianness. 您没有提到要定位的平台,但是请记住,这没有关注字节序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.