^X

Interpret a string as a hexadecimal number

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
hex = ^X(expression[, size])

Return value

hex

The integer value of an alpha expression, evaluated as a hexadecimal number. If expression is null, ^X returns a value of 0. (i)

Arguments

expression

The expression to interpret. (a)

size

(optional) A value that specifies the size of the resulting integer. Valid values are

1 = The result is returned in an i1 value.

2 = The result is returned in an i2 value.

4 = The result is returned in an i4 value.

8 = The result is returned in an i8 value.

Discussion

You can specify unquoted arguments with ^X. For example:

^x(F4)

If expression does not contain only valid hexadecimal digits (0 through 9 and A through F), a “Hexadecimal digits expected in argument (string)” error ($ERR_HDIGXP) occurs.

By default, ^X produces an i4 value if the return value fits in 32 bits or an i8 value if the return value is larger than 32 bits. If size is specified, the value is returned in an integer of that size. If the value exceeds the specified size, it is truncated to fit. When used as the initial value of an automatically sized integer field, the field size is determined by the magnitude of the ^X result, not the size returned by ^X .

An ^X value that fits in 32 bits but has the high bit set will be negative. If you want a positive value when a negative i4 would normally be returned, specify a value of 8 in the optional size argument.

Note

^X only returns the low 32 bits of the converted expression.

Examples

This example uses alpha input as data for a hexadecimal arithmetic computation. If the alpha variable contains any nonnumeric data other than a blank, a decimal point, or a sign (+ or –), a “Bad digit encountered” error ($ERR_DIGIT) is generated.

subroutine math 
    a_avar      ,a 
record 
    val1        ,d5 
    val2        ,d5 
    result      ,d10 
proc 
    result = (val1*val2) / ^x(a_avar) 
    .
    .
    .
    xreturn 
endsubroutine