X2D (Hexadecimal to Decimal)

 ───X2D(hexstring ─┬─────┬─)──────
                     └─,n──┘

X2D converts hexstring (a string of hexadecimal characters) to decimal. If the result cannot be expressed as a whole number, an error results. That is, the result must have no more digits than the current setting of NUMERIC DIGITS.

You can optionally add blanks to hexstring (at byte boundaries only, not leading or trailing positions) to aid readability; they are ignored.

If hexstring is null, X2D returns 0.

If n is not specified, hexstring is processed as an unsigned binary number.

Here are some examples:

X2D('0E')        ->    14
X2D('81')        ->    129
X2D('F81')       ->    3969
X2D('FF81')      ->    65409
X2D('c6 f0'X)    ->    240

If n is specified, the given sequence of hexadecimal digits is padded on the left with zeros (note, not sign-extended), or truncated on the left to n characters. The resulting string of n hexadecimal digits is taken to be a signed binary number-positive if the leftmost bit is OFF, and negative, in two's complement notation, if the leftmost bit is ON. If n is 0, X2D returns 0.

Here are some examples:

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


[Back: X2C (Hexadecimal to Character)]
[Next: Queue Interface]