hex to binary

Home Forums General Using Ctrlr hex to binary

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #72869
    hutch
    Participant
      • Topics: 2
      • Replies: 1
      • Total: 3

      Hi

      What would be the best way to convert specific bytes in a data string to binary? For example in a string “F0 05 05 0f 07”, I would like to convert 0f to 00001111 and 07 to 00000111. These individual bits will be used to set specific uiButtons on a panel.

      Thank you !

      #72870
      goodweather
      Participant
        • Topics: 45
        • Replies: 550
        • Total: 595
        • ★★★

        Hi, do you really need the specific binary display with 0 and 1?
        Normally, getting the actual value (in whatever base) would be good enough
        So supposing you can just give that value, it is enough to just use

        tonumber(string.sub(your_data_string, start_pos, start_pos+1),16)
        -- tonumber("0A",16) gives 10
        #72872
        hutch
        Participant
          • Topics: 2
          • Replies: 1
          • Total: 3

          Many thanks Sir Goodweather. That worked well for my purposes.

        Viewing 3 posts - 1 through 3 (of 3 total)
        • The forum ‘Using Ctrlr’ is closed to new topics and replies.
        There is currently 0 users and 71 guests online
        No users are currently active
        Forum Statistics
        Threads: 2,495, Posts: 17,374, Members: 77,605
        Most users ever online was 12 on January 22, 2019 3:47 pm
        Ctrlr