BinaryToInteger (String function): Difference between revisions
m (1 revision) |
m (first pass, match syntax diagram to template and fix tags; still some broken links) |
||
Line 1: | Line 1: | ||
{{Template:String:BinaryToInteger subtitle}} | {{Template:String:BinaryToInteger subtitle}} | ||
<var>BinaryToInteger</var> is an <var>[[Intrinsic classes|intrinsic]]</var> 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. | |||
The string may contain no more than four characters. | |||
==Syntax== | ==Syntax== | ||
{{Template:String:BinaryToInteger syntax}} | {{Template:String:BinaryToInteger syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%number</th> | ||
<td>A numeric variable to receive the integer value of the | <td>A numeric variable to receive the integer value of the method object <var class="term">string</var>.</td></tr> | ||
<tr><th>string</th> | <tr><th><var class="term">string</var></th> | ||
<td>A binary string value. | <td>A binary string value. The string's length must be four characters or less, but greater than zero.</td></tr> | ||
<tr><th>Signed | <tr><th><var class="term">Signed</var></th> | ||
<td>This name | <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. <var class="term">Signed</var> is an optional argument that defaults to <code>False</code>, which produces an unsigned conversion. 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.</p></td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul><li>The <var>BinaryToInteger</var> function is available as of <var class=product>Sirius Mods</var> version 7.3.</ul> | |||
==Examples== | ==Examples== | ||
<ol><li>The following statement displays <code>240</code>: | |||
<p class="code">printText {'0':binaryToInteger} | |||
</p> | |||
<li>The following statement displays <code>61680</code>: | |||
<p class="code">printText {'00':binaryToInteger} | |||
<p class="code"> | |||
</p> | </p> | ||
< | <li>The result of the following pair of statements is <code>-3856</code>: | ||
<p class="output">%string = '00' | <p class="output">%string = '00' | ||
printText {%string:binaryToInteger(signed=true)} | printText {%string:binaryToInteger(signed=true)} | ||
</p> | |||
<li>The result of the following pair of statements is <code>0</code>: | |||
<p class="output">%string = '00':hexToString | |||
printText {%string:binaryToInteger} | |||
</p> | </p> | ||
</ol> | |||
==See also== | ==See also== | ||
<ul><li>For information about the PrintText statement, pleae see <var>[[Intrinsic classes#printtext|printText]]</var>. | |||
<li>The inverse of <var>BinaryToInteger</var> is <var>[[IntegerToBinary (Float function)|IntegerToBinary]]</var>.</ul> | |||
{{Template:String:BinaryToInteger footer}} | {{Template:String:BinaryToInteger footer}} |
Revision as of 04:09, 31 January 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; if you specify a value, the parameter name Signed is required. Signed is a boolean enumeration value that indicates whether the method object string is converted to a signed integer. Signed is an optional argument that defaults to |
Usage notes
- The BinaryToInteger function is available as of Sirius Mods version 7.3.
Examples
- The following statement displays
240
:printText {'0':binaryToInteger}
- The following statement displays
61680
:printText {'00':binaryToInteger}
- The result of the following pair of statements is
-3856
:%string = '00' printText {%string:binaryToInteger(signed=true)}
- The result of the following pair of statements is
0
:%string = '00':hexToString printText {%string:binaryToInteger}
See also
- For information about the PrintText statement, pleae see printText.
- The inverse of BinaryToInteger is IntegerToBinary.