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

    Python hex conversion

    Scheduled Pinned Locked Moved Discussion
    pythonble
    2 Posts 2 Posters 214 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.
    • M Offline
      misterlisty
      last edited by

      How to convert service = b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb\xaa\xed\xde'

      to

      DEEDAAFB-000-0000-0000-000000000002

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

        @misterlisty
        s = "".join(["%02X" % b[i] for i in range(len(service) - 1,-1,-1)])
        resulting in:
        DEEDAAFB000000000000000000000001
        sm = s[:8] + "-" + s[8:12] + "-" + s[12:16]+"-"+ s[16:20] + "-" + s[20:]
        resulting in:
        DEEDAAFB-0000-0000-0000-000000000001

        Which is however on letter longer than the string above. So check whether in the second group it is really three 0's.

        Edit: for the second step, you can also write:
        sm = "-".join([s[:8], s[8:12], s[12:16], s[16:20], s[20:]])

        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