int.from_bytes bug?
-
Statements
print(int.from_bytes(b'\xFF\x00','little'))
print(int.from_bytes(b'\xFF\x00','big'))print both 255. Expected: 65280 for big endian.
Can someone confirm this issue, and if correct, how do I file a bug report?
-
@bmarkus I tested that too on MP ESP8266 and ESP32. Therefopre I searched back about the issue and it's fix in the MP.org repository.
-
@robert-hh said in int.from_bytes bug?:
It looks like this was fixed in the original micropython.org branch in January with PR #2791
Tested on recent micropython unix version it works as expected.
-
@ttmetro said in int.from_bytes bug?:
int.from_bytes(b'\xFF\x00','big')
Confirmed. A buf report is filed by raising ans issue here:
https://github.com/pycom/pycom-micropython-sigfox/issues
Click on the button "New Issue", give it a meaningful title and an explanation, like you did above.
It looks like this was fixed in the original micropython.org branch in January with PR #2791
Until it's fixed, you can use ustruct.unpack() like:
import ustruct
ustruct.unpack("<H", b'\xFF\x00')[0]
255
ustruct.unpack(">H", b'\xFF\x00')[0]
65280
ustruct.unpack(">h", b'\xFF\x00')[0]
-256
And ustruct.pack for the equivalent of to_bytes.