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?
-
@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. -
@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.
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login