Home Contents | # string.tohex | String | Core4 Lua Commands

## SYNOPSIS

result = string.tohex(s [, i [, j [, map]]])

## DESCRIPTION

Converts s into it's hexadecimal ASCII representation.

When i and/or j are given, uses the substring s[i], s[i+1], …, s[j].
The default value for i is 1; the default value for j is the number of characters in s.

The optional string parameter map sets the mapping from the nibble values 0…F to the characters used in the output. The default value is "0123456789ABCDEF".

## RETURN VALUE

String, ASCII text. The result has exactly twice the length of data.

## ERRORS

Passed data must be a string or a number, or else an error is thrown.

## EXAMPLE

>
print(string.tohex("ABCD4*"))
41424344342A

## SEE ALSO

string.fromhex, string.from64, string.to64, string.hexdump