string.format("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", string.byte(str,1,16))
How can I convert a UUID from binary format to string format in Lua?
Question
I have a UUID in binary format in my Lua program (just 16 bytes in string). I need to convert it to string format, for example 550e8400-e29b-41d4-a716-446655440000
.
How can I convert it?
La solution 2
Autres conseils
Here's a program to convert a 2 bytes string to its hex format:
local str = "\x55\x0e"
local result = string.format("%02x%02x", string.byte(str, 1, 2))
print(result)
Output: 550e
string.byte
gets the internal numeric representation of the characters, and then use string.format
to get the hex format.
You can extend it to convert a UUID yourself.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow