簡體   English   中英

將字節數組轉換為 int python 錯誤結果

[英]Convert bytes array to int python wrong result

我知道這應該很容易,但我就是無法為 python 找到正確的語法。

我的 int 沒有正確轉換。 這是我的 2 個打印語句的 output。 我的 output 應該是9718而不是959918392

bytearray(b'9718')
959918392

這是我的轉變。 我不明白我在做什么錯。

print(size)
print(int.from_bytes(size, byteorder='big'))

您嘗試的假設數字直接編碼為字節。 您實際上想從 ascii 中解析它,您可以這樣做:

int(b'9718'.decode('ascii'))

暫無
暫無

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

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