X2D
Converts a hexadecimal string into an integer.
Type
String function
Format
X2D('hex' [flag]) - hex
- The hexadecimal string to be converted to an integer. The maximum length is 8 characters.
- flag
- A boolean flag that controls the way hex is
processed:
- 0
- It is considered signed; that is, if the leading character is 8 through F, the value is negative. This is the default.
- 1
- It is considered unsigned (see “Usage Notes®”).
Usage Notes
- Use X2D and its companion dialog function, D2X, to perform hexadecimal
calculations. One way might be:
- Accept strings of hex characters from a terminal user.
- Convert the character string to a signed number using X2D.
- Perform the operation using the signed numbers.
- Convert the resulting signed number to a character string using D2X.
- Display the result to the terminal user.
- The dialog fails if hex is longer than 8 characters, or contains characters other than a-f, A-F, and 0-9.
- You can use the LENGTH and VERIFY functions to validate hex prior to passing it to X2D.
- If hex is null, 0 is returned.
- Because CL/SuperSession integers are signed fullwords, an 8-character hex string that has the high bit on will be converted to a negative value regardless of the flag value.
Example
The following example sets D to 12488:
set D (x2d('30C8'))The
following example sets D to -3067:
set D (x2d('F405'))The default is to treat the value as signed.
The following example sets D to
62469:
set D (x2d('F405' 1))