$X2D: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 14: Line 14:
The leading bit of the hexadecimal string is repeated out to the length derived from the second argument. If the length is less than the length of the hexadecimal string, the leftmost digits of the hexadecimal string are dropped. The hexadecimal string represents an integer using 2's complement.
The leading bit of the hexadecimal string is repeated out to the length derived from the second argument. If the length is less than the length of the hexadecimal string, the leftmost digits of the hexadecimal string are dropped. The hexadecimal string represents an integer using 2's complement.
==Syntax==
==Syntax==
<p class="syntax"><section begin="syntax" /> %VALUE = $X2D(hex_string, width)
<p class="syntax"><section begin="syntax" />%VALUE = $X2D(hex_string, width)
<section end="syntax" /></p>
<section end="syntax" /></p>
<p class="caption">$X2D Function
<p class="caption">$X2D Function

Revision as of 20:33, 24 October 2012

Convert hex string to integer

Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $X2D function is the HexToInteger (String function) or the HexToString (String function). For a full list of string and numeric conversion functions see List of String methods and List of Float methods.

The $X2D function returns the integer which is represented by the hexadecimal input string.

$X2D accepts two optional arguments and returns a numeric value.

The first argument is the hex string to be converted to an integer. If it is omitted or is the null string or contains characters other than '0' through '9', 'A' through 'F', or 'a' through 'f', zero is the result.

The second argument is the number of characters to use from the string. If it is omitted or is greater than 8, 8 characters are used. If, after conversion to an integer, it is 0 or less, or can't be represented as a 31 bit value, zero is the result of $X2D.

The leading bit of the hexadecimal string is repeated out to the length derived from the second argument. If the length is less than the length of the hexadecimal string, the leftmost digits of the hexadecimal string are dropped. The hexadecimal string represents an integer using 2's complement.

Syntax

<section begin="syntax" />%VALUE = $X2D(hex_string, width) <section end="syntax" />

$X2D Function

%VALUE is set to the integer represented in 2's complement by the hexadecimal string.

The following program will print the value -1:

B PRINT $X2D('0F', 1) END

Products authorizing $X2D