簡體   English   中英

從TArray提取float32 <uint8>

[英]Extract float32 from TArray<uint8>

虛幻引擎(C ++)

嗨,我有一個來自TCP連接的字節數組。 我有58字節的標頭和12 x 4字節的Float32。 我需要從數組字節中提取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個字節,並根據該值創建一個浮點數,這不是您想要的。

您可以使用reinterpret_cast讀取數據:

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

您沒有提到要定位的平台,但是請記住,這沒有關注字節序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM