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

    Convert string to hex

    SOFTWARE
    2
    3
    2.4k
    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
      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
        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
          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
          • First post
            Last post