conv Function
Introduction
The conv
function is used to convert a number from one base to another. It supports conversions between bases 2 and 36 and can handle both signed and unsigned numbers.
Syntax
Parameters
num
:STRING
type, representing the number to be converted. The number is expressed as a string, and its base is specified byfromBase
.fromBase
:INTEGER
type, representing the base of the source number. The value range is from 2 to 36.toBase
:INTEGER
type, representing the target base. The value range is from 2 to 36.
Return Value
Returns a STRING
type result, representing the converted number.
- If
fromBase
is less than 2 or greater than 36, or iftoBase
is less than 2 or greater than 36, the function returnsNULL
. - If
toBase
is negative, the numbernum
is interpreted as a signed number; otherwise, it is treated as an unsigned number.
Examples
Example 1: Binary to Decimal
Example 2: Hexadecimal to Decimal
Example 3: Decimal to Hexadecimal