tobase16

function tobase16( str ) --> base16str

Description

Encodes a data string to a base 16 string.

Parameters

str

The data string that should be encoded.

Return Values

base16str

The base 16 encoded string.

Code

--ZFUNC-tobase16-v1
local function tobase16( str ) --> base16str
   return ( str:gsub( '.', function ( c )
               return string.format('%02X', string.byte( c ) )
            end ) )
end

return tobase16

Examples

local t = require( "taptest" )
local tobase16 = require( "tobase16" )

-- should convert data to a hex string
t( tobase16( "Hello world!" ), "48656C6C6F20776F726C6421" )

t()

Inspired by

See also