FROM_BASE()

All functions > MATH > FROM_BASE()

Returns the decimal (base 10) equivalent of a number expressed in a specified base.

Signatures

From base

Returns: Decimal equivalent

FROM_BASE(number_string: VARCHAR, base: B) → BIGINT
sql
ParameterTypeRequiredDescription
number_stringVARCHARYesString representation of the number in the source base
baseBYesSource base, from 2 to 36

With:

  • B : Integer type (TINYINT … BIGINT)

Signature notes:

  • Supports bases from 2 (binary) to 36
  • For bases > 10, uses letters A-Z for digits 10-35, case insensitive
  • Reads an optional + or - sign, then at least one digit below the base: '-FF' is -255
  • Raises FROM-BASE-INVALID-NUMBER at runtime on any other text (spaces, an empty string, a digit outside the base) or a value outside the BIGINT range
  • Returns NULL if number_string or base is NULL

Availability

StatusBackends
Not availablemysql

Examples

FeatureQL
RETURN
    -- Binary to decimal
    f1 := FROM_BASE('1010', 2),
    -- Octal to decimal
    f2 := FROM_BASE('777', 8),
    -- Hexadecimal to decimal
    f3 := FROM_BASE('FF', 16),
    -- Hex word to decimal
    f4 := FROM_BASE('CAFE', 16),
    -- Signed, case insensitive
    f5 := FROM_BASE('-zz', 36),
    -- Smallest BIGINT
    f6 := FROM_BASE('-8000000000000000', 16)
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINTf5 BIGINTf6 BIGINT
1051125551966-1295-9223372036854776000