gpt4 book ai didi

c++ - 从 TArray 中提取 float32

转载 作者:行者123 更新时间:2023-11-28 04:53:56 32 4
gpt4 key购买 nike

虚幻引擎(C++)

您好,我有一个来自 TCP 连接的 TArray of Bytes。我有 58 字节的 header 和 12 x 4 字节的 Float32。我需要从我的 Array Bytes 中提取 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));

有人可以帮助我吗?

套接字:https://github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/index.md

转换(12x4 字节):https://github.com/openigtlink/OpenIGTLink/blob/release-3.0/Documents/Protocol/transform.md

最佳答案

float(ReceivedData[58]) 将从 ReceivedData 中取消引用第 58 个字节,并根据该值创建一个 float ,这不是您想要的。

可以使用reinterpret_cast读取数据:

float value = *(reinterpret_cast<float*>(ReceivedData + 58));

您没有提到您的目标平台,但请记住,这不会关注字节顺序。

关于c++ - 从 TArray<uint8> 中提取 float32,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47591237/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com