hex to binary

Home Forums General Using Ctrlr hex to binary

This topic contains 2 replies, has 2 voices, and was last updated by  hutch 9 months, 2 weeks ago.

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
    goodweather
    Participant
    • Topics: 38
    • Replies: 321
    • Total: 359
    • ★★

    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)

You must be logged in to reply to this topic.

There is currently 0 users and 15 guests online
No users are currently active
Forum Statistics
Threads: 2,130, Posts: 14,980, Members: 9,858
Most users ever online was 5 on March 28, 2018 6:11 pm
Do NOT follow this link or you will be banned from the site!