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( "tapered" )
local tobase16 = require( "tobase16" )

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

t.done()

Inspired by

See also