Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    int.from_bytes bug?

    Scheduled Pinned Locked Moved MicroPython
    buit-in library
    4 Posts 3 Posters 1.3k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      ttmetro
      last edited by

      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?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @ttmetro
        last edited by robert-hh

        @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.

        1 Reply Last reply Reply Quote 1
        • bmarkusB Offline
          bmarkus
          last edited by

          @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.

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @bmarkus
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0

            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
            • 1 / 1
            • First post
              Last post

            Pycom on Twitter

            Pycom