aboutsummaryrefslogtreecommitdiffstats
path: root/util/hex.lua
blob: b21ee17e5fe9cb96e4986f9fab89a0570cd4f97e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local s_char = string.char;

local function char_to_hex(c)
	return ("%02x"):format(c:byte())
end

local function hex_to_char(h)
	return s_char(tonumber(h, 16));
end

local function to(s)
	return s:gsub(".", char_to_hex);
end

local function from(s)
	return s:gsub("..", hex_to_char);
end

return { to = to, from = from }