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
| Parameter | Type | Required | Description |
|---|---|---|---|
number_string | VARCHAR | Yes | String representation of the number in the source base |
base | B | Yes | Source 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
| Status | Backends |
|---|---|
| Not available | mysql |
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 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT | f5 BIGINT | f6 BIGINT |
|---|---|---|---|---|---|
| 10 | 511 | 255 | 51966 | -1295 | -9223372036854776000 |
On this page