🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Convert string to hex

    Scheduled Pinned Locked Moved SOFTWARE
    3 Posts 2 Posters 3.6k Views
    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.
    • S Offline
      shahabdhafiz
      last edited by

      Hi all..
      I am using M5Stack Core 2. Anyone can help me on converting string to hex. I got string from the uart and I want to convert them to hex value. I couldn't find on how to do it in Blocky or in micropython. One of the example I follow on youtube can't be used. The link is https://www.youtube.com/watch?v=SHylh5iaVXI

      1 Reply Last reply Reply Quote 0
      • IAMLIUBOI Offline
        IAMLIUBO
        last edited by

        hi @shahabdhafiz

        You can try this way:

        a = "0x0A"
        b = int(a, 16)
        print(b)
        

        docs is here: link

        S 1 Reply Last reply Reply Quote 0
        • S Offline
          shahabdhafiz @IAMLIUBO
          last edited by

          @iamliubo hi, thanks for the reply.

          I managed to do the example from what you gave and I got the results as it is. but, after several checking, I received bytes from the uart. Then, I need to convert to hex. the method i used is:

          hexVal = hex(int.from_bytes(serData, "big"))
          label14.set_text(str(hexVal)) //to show the hexVal to the label
          

          I got the idea from the example you gave and THANK YOU so much for that =)

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