1

This is my first lua project so I am sorry if this question is basic.

So I am trying to convert a string to ascii hex values. I have used the string.byte to convert them in to the decimal ascii but I need to have the corresponding hex value instead. Each of the 7 specific values I am taking from the string uses

local a = (string.byte(x, 1) or '00')

It all works as expected, however the device needs the hex ascii values to display the correct character. Can I add to each line to convert them to the hex value easily?

1 Answer 1

4

Do local a = string.format('%02x', string.byte(x, 1)). Remember that numbers are just numbers, not decimal or hexadecimal, and that it's string representations that are decimal or hexadecimal.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.