Product SiteDocumentation Site

7.4.81. X2D (Hexadecimal to Decimal)


>>-X2D(hexstring--+----+--)------------------------------------><
                  +-,n-+

Returns the decimal representation of hexstring. The hexstring is a string of hexadecimal characters. If the result cannot be expressed as a whole number, an error occurs. That is, the result must not have more digits than the current setting of NUMERIC DIGITS.
You can optionally include whitespace characters in hexstring (at byte boundaries only, not leading or trailing) to aid readability; they are ignored.
If hexstring is null, the function returns 0.
If you do not specify n, the hexstring is processed as an unsigned binary number.
Here are some examples:

Example 7.110. Builtin function X2D

X2D("0E")        ->    14
X2D("81")        ->    129
X2D("F81")       ->    3969
X2D("FF81")      ->    65409
X2D("46 30"X)    ->    240          /*  ASCII   */
X2D("66 30"X)    ->    240          /*  ASCII   */

If you specify n, the string is taken as a signed number expressed in n hexadecimal digits. If the leftmost bit is off, then the number is positive; otherwise, it is a negative number. In both cases it is converted to a whole number, which can be negative. If n is 0, the function returns 0.
If necessary, hexstring is padded on the left with 0 characters (not "sign-extended"), or truncated on the left to n characters.
Here are some examples:

Example 7.111. Builtin function X2D

X2D("81",2)      ->    -127
X2D("81",4)      ->    129
X2D("F081",4)    ->    -3967
X2D("F081",3)    ->    129
X2D("F081",2)    ->    -127
X2D("F081",1)    ->    1
X2D("0031",0)    ->    0