[英]Converting between multiline and single-line (with escaped linebreaks) string representations in Python?
[英]converting between number representations cpp and python
我正在使用以下代碼將 cpp 中的浮點數(在 arduino 上)轉換為 integer 表示:
float temp = 22.8;
uint32_t temp_as_integer;
static_assert(sizeof(temp) == sizeof(temp_as_integer), "sizes don't match");
memcpy(&temp_as_integer, &temp, sizeof(temp_as_integer));
這通過串行發送到另一台計算機,然后需要轉換回 python 中的浮點數。
這就是我卡住的地方。 有人可以指出我正確的方向來做 python 中的 cpp 過程的逆過程嗎?
整數和浮點數在內部具有完全不同的表示。 如果您將其發送到另一台計算機,則將其轉換回正確浮點數的機會非常小(特別是如果芯片組架構不同,或者如果一個是大端,另一個是小端)。 也許值得將其序列化為字符串? 在性能/帶寬方面你能負擔得起嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.