Software /
code /
prosody
File
util/hex.lua @ 6375:76d8907d5301
util.hex: Small util lib for converting to/from hex strings
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 02 Sep 2014 17:56:42 +0100 |
child | 6384:3f4809d01783 |
line wrap: on
line source
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 function to(s) return s:gsub(".", char_to_hex); end function from(s) return s:gsub("..", hex_to_char); end return { to = to, from = from }