BinaryToInteger (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (re-match syntax diagram to revised template; fix tags. Still some link targets that need to be found / written.)
Line 9: Line 9:
<tr><th>%number</th>
<tr><th>%number</th>
<td>A numeric variable to receive the integer value of the method object <var class="term">string</var>.</td></tr>
<td>A numeric variable to receive the integer value of the method object <var class="term">string</var>.</td></tr>
<tr><th><var class="term">string</var></th>
<tr><th>string</th>
<td>A binary string value. The string's length must be four characters or less, but greater than zero.</td></tr>
<td>A binary string value. The string's length must be four characters or less, but greater than zero.</td></tr>
<tr><th><var class="term">Signed</var></th>
<tr><th>Signed</th>
<td>This is an optional, but <var>[[Methods#Named parameters|NameRequired]]</var>, argument is a <var>[[boolean enumeration]]</var>; if you specify a value, the parameter name <var class="term">Signed</var> is required.<p><var class="term">Signed</var> is a <var>[[boolean enumeration]]</var> value that indicates whether the method object string is converted to a signed integer.<ul><li><var class="term">Signed</var> is an optional argument that defaults to <code>False</code>, which produces an unsigned conversion.<li>If <code>Signed=True</code>, the method object <var class="term">string</var> is treated as if it were preceded by a negative sign, a two's complement conversion is performed, and the returned value is preceded by a negative sign.</ul></p></td></tr>
<td>This is an optional, but <var>[[Methods#Named parameters|NameRequired]]</var>, argument is a <var>[[boolean enumeration]]</var> that indicates whether the method object <var class="term">string</var> is to be converted to a signed integer or not.<ul><li><var class="term">Signed</var> defaults to <code>False</code>, which produces an unsigned conversion.<li>If <code>Signed=True</code>, the method object <var class="term">string</var> is treated as if it were preceded by a negative sign, a two's complement conversion is performed, and the returned value is preceded by a negative sign.</ul></td></tr>
</table>
</table>



Revision as of 02:17, 2 February 2011

Convert a binary string to an integer (String class)


BinaryToInteger is an intrinsic function that treats a string as if it were binary and converts it to an integer. The string may contain no more than four characters.

Syntax

%number = string:BinaryToInteger[( [Signed= boolean])]

Syntax terms

%number A numeric variable to receive the integer value of the method object string.
string A binary string value. The string's length must be four characters or less, but greater than zero.
Signed This is an optional, but NameRequired, argument is a boolean enumeration that indicates whether the method object string is to be converted to a signed integer or not.
  • Signed defaults to False, which produces an unsigned conversion.
  • If Signed=True, the method object string is treated as if it were preceded by a negative sign, a two's complement conversion is performed, and the returned value is preceded by a negative sign.

Usage notes

  • The BinaryToInteger function is available as of Sirius Mods version 7.3.

Examples

  1. The following statement displays 240:

    printText {'0':binaryToInteger}

  2. The following statement displays 61680:

    printText {'00':binaryToInteger}

  3. The result of the following pair of statements is -3856:

    %string = '00' printText {%string:binaryToInteger(signed=true)}

  4. The result of the following pair of statements is 0:

    %string = '00':hexToString printText {%string:binaryToInteger}

See also