How do i convert string.byte to their ascii hex value

Viewed 42

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 Answers

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.

Related