Home Contents | # mpi:toString | Cipher/MPI | Core4 Lua Commands

## SYNOPSIS

1. str = mpi:toString([radix_or_alphabet [, length]])
2. str = tostring(mpi)

## DESCRIPTION

The Core4 system includes a copy of mbed TLS.

Converts the stored number into an ASCII string.

The variable radix_or_alphabet controls the output format.

When radix_or_alphabet is a number, it specifies the radix (i.e. number base) of the output. Allowed range is 2...36. For bases larger than 10, encoding uses the upper case letters of the alphabet as additional digits.

When radix_or_alphabet is a string, it specifies the conversion alphabet. The output radix equals the length of the alphabet string. The first character in the string is used to encode a zero, the second character encodes the one, and so on.

The default value for radix_or_alphabet is the number 10.

The optional argument length specifies the desired length of the output string. If length is shorter than required by the number, the output is truncated from the left. If length is longer than required by the number, the output is padded on the left hand side. Padding uses zeroes (which is the first character of the alphabet string, when using alphabet mode).

The second form provides the Lua default string conversion operation. This call is fixed to the decimal radix. This function enables using a mpi as an argument to print and getting the number as expected.

## RETURN VALUE

Returns a string on success.

In case of an error returns three values: nil, a string describing the error and a negative error code from the underlying mbed TLS implementation.

## SEE ALSO

mpi:fromString