【问题标题】:Extract float32 from TArray<uint8>从 TArray<uint8> 中提取 float32
【发布时间】:2017-12-01 10:21:06
【问题描述】:

虚幻引擎 (C++)

嗨,我有一个来自 TCP 连接的 TArray 字节。我有 58 字节的标头和 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

【问题讨论】:

    标签: c++ sockets unreal-engine4


    【解决方案1】:

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

    您可以使用reinterpret_cast读取数据:

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

    您没有提及您所针对的平台,但请记住,这不注意字节顺序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 2022-01-15
      • 2017-03-08
      • 2021-01-07
      • 2020-05-16
      • 1970-01-01
      • 2019-12-11
      相关资源
      最近更新 更多