BinaryToInteger (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 2: Line 2:


This [[Intrinsic classes|intrinsic]] function treats a string as if it were binary and converts it to an integer.
This [[Intrinsic classes|intrinsic]] function 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 [[Sirius Mods]].                          
The BinaryToInteger function is available as of version 7.3 of the [[Sirius Mods]].
==Syntax==
==Syntax==
{{Template:String:BinaryToInteger syntax}}
{{Template:String:BinaryToInteger syntax}}
Line 16: Line 16:
<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>
<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>
</table>
</table>
                                                                   
 
==Usage notes==
==Usage notes==
*The inverse of the BinaryToInteger method is [[IntegerToBinary (Float function)|IntegerToBinary]].
*The inverse of the BinaryToInteger method is [[IntegerToBinary (Float function)|IntegerToBinary]].


==Examples==
==Examples==
                                                                 
 
Several examples follow.                                        
Several examples follow.
*The following statement displays ''''240'''':                  
*The following statement displays ''''240'''':
     [[Intrinsic classes#printtext|printText]] {'0':binaryToInteger}      
     [[Intrinsic classes#printtext|printText]] {'0':binaryToInteger}
*The following statement displays ''''61680'''':                
*The following statement displays ''''61680'''':
     printText {'00':binaryToInteger}                            
     printText {'00':binaryToInteger}
                                                                 
 
*The result of the following pair of statements is ''''-3856'''':  
*The result of the following pair of statements is ''''-3856'''':
     %string = '00'                                              
     %string = '00'
     printText {%string:binaryToInteger(signed=true)}            
     printText {%string:binaryToInteger(signed=true)}
                                                                 
 
*The result of the following pair of statements is ''''0'''':    
*The result of the following pair of statements is ''''0'''':
     %string = '00':hexToString                                  
     %string = '00':hexToString
     printText {%string:binaryToInteger}
     printText {%string:binaryToInteger}


===See also===                                                                                        
===See also===
[[List of intrinsic String methods]]
[[List of intrinsic String methods]]


[[Category:Intrinsic String methods|BinaryToInteger function]]
[[Category:Intrinsic String methods|BinaryToInteger function]]
[[Category:Intrinsic methods]]
[[Category:Intrinsic methods]]

Revision as of 14:04, 19 January 2011

Convert a binary string to an integer (String class)


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

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

Syntax

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

Syntax terms

%num 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=bool 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.

Usage notes

Examples

Several examples follow.

  • 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

List of intrinsic String methods