BinaryToInteger (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(25 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Template:String:BinaryToInteger subtitle}}
{{Template:String:BinaryToInteger subtitle}}


This [[Intrinsic classes|intrinsic]] function treats a string as if it were binary and converts it to an integer.
<var>BinaryToInteger</var> is an [[Intrinsic classes|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.
The string may contain no more than four characters.


The BinaryToInteger function is available as of version 7.3 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:String:BinaryToInteger syntax}}
{{Template:String:BinaryToInteger syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%num                                                                                                      </th>
<tr><th nowrap>%number</th>
<td>A numeric variable to receive the integer value of the                                                   method object string.                                                                                         </td></tr>
<td>A numeric variable to receive the integer value of the method object <var class="term">string</var>.</td></tr>
<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>
<tr><th>string</th>
<tr><th>Signed=bool  </th>
<td>A binary string value. The string's length must be four characters or fewer but greater than zero.</td></tr>
<td>This name-required argument (''''Signed'''') is a boolean value      that indicates whether the method object string is converted             to a signed integer.                                                     If ''''True'''',                                                         the method object 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,                                                                                            Signed is an optional argument that defaults to ''''False'''', which    produces an unsigned conversion.</td></tr>
 
<tr><th><var>Signed</var></th>
<td>This optional, but [[Notation conventions for methods#Named parameters|name required]], 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>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>


==Usage notes==
==Usage notes==
*The inverse of the BinaryToInteger method is [[IntegerToBinary (Float function)|IntegerToBinary]].
<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 statement|printText]] {'0':binaryToInteger}
</p>


Several examples follow.
<li>The following statement displays <code>61680</code>:
*The following statement displays ''''240'''':
<p class="code">printText {'00':binaryToInteger}
    [[Intrinsic classes#printtext|printText]] {'0':binaryToInteger}
</p>
*The following statement displays ''''61680'''':
    printText {'00':binaryToInteger}


*The result of the following pair of statements is ''''-3856'''':
<li>The result of the following pair of statements is <code>-3856</code>:
    %string = '00'
<p class="output">%string = '00'
    printText {%string:binaryToInteger(signed=true)}
printText {%string:binaryToInteger(signed=true)}
</p>


*The result of the following pair of statements is ''''0'''':
<li>The result of the following pair of statements is <code>0</code>:
    %string = '00':hexToString
<p class="output">%string = '00':hexToString
    printText {%string:binaryToInteger}
printText {%string:binaryToInteger}
</p>
</ol>


==See also==
==See also==
[[List of intrinsic String methods]]
<ul>
<li>The inverse of <var>BinaryToInteger</var> is <var>[[IntegerToBinary (Float function)|IntegerToBinary]]</var>.
</ul>


[[Category:String methods|BinaryToInteger function]]
{{Template:String:BinaryToInteger footer}}
[[Category:Intrinsic methods]]

Latest revision as of 15:41, 17 March 2016

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 fewer but greater than zero.
Signed This optional, but name required, 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