NET/MASTER Network Control Language (NCL) Reference Manual
X2D
Built-in Functions
4–112 106126 Tandem Computers Incorporated
X2D The X2D built-in function converts a hexadecimal string to a decimal number. The
maximum number of hexadecimal digits allowed is eight.
X2D(
string
[,
n
] )
string
specifies the input string that is converted.
n
specifies an optional number that defines the significant width, in hexadecimal
digits. If specified, the truncated string is treated as a signed binary number. If
n
is 0, 0 (zero) is returned. A compilation error results if
n
is greater than the length
of
string
.
If
n
is provided, the string is truncated from the right to
n
bytes before conversion.
The result, after truncation, is converted and treated as a 2’s complement signed
binary number. The conversion of a positive hexadecimal number can result in a
negative decimal number if the result, after truncation, has a 1 in bit zero. By
convention, a 2’s complement signed binary number has its leading bit set to 1 if it
is negative. See the second example of this built-in function.
Considerations
If only
string
is provided, the string is treated as an unsigned binary number.
See also C2D, D2C and D2X. The C2D built-in function converts a character string
to a decimal number; the D2C built-in function converts a decimal number to an
ASCII character string; the D2X built-in function converts a decimal number to a
hexadecimal string.
Examples
In the following example, the hexadecimal string “0B” is converted to the whole
number 11:
&A = 0B
&RESULT = X2D(&A)
In the following example, the hexadecimal string “0b0c0a0f” is converted to -1. The
truncation of the given string to 1 byte from the right, leaves the hexadecimal value ‘f’,
which after conversion, gives the decimal value -1:
SAY X2D(0b0c0a0f,1)
In the following example, the hexadecimal string “0b0c0a0f” is converted to 15. The
truncation of the given string to two bytes from the right leaves the hexadecimal value
‘0f’, which, after conversion, gives the decimal value 15:
SAY X2D(0b0c0a0f,2)