IntegerToBinary (Float function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
 
(22 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Template:Float:IntegerToBinary subtitle}}
{{Template:Float:IntegerToBinary subtitle}}


This [[Intrinsic classes|intrinsic]] function converts an integer to its binary string representation.
The <var>IntegerToBinary</var> [[Intrinsic classes|intrinsic]] function converts an integer to its binary string representation. Only integers that convert to a string no longer than four characters are allowed.
Only integers that convert to a string no longer than four characters are allowed.


The IntegerToBinary function is available as of version 7.3 of the [[Sirius Mods]].
==Syntax==
==Syntax==
{{Template:Float:IntegerToBinary syntax}}
{{Template:Float:IntegerToBinary syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%str </th>
<tr><th>%string</th>
<td>A string variable to receive the converted value of the method object number. </td></tr>
<td>A string variable to receive the converted value of the method object <var class="term">float</var>.</td></tr>
<tr><th>number </th>
 
<td>An integer value. The number must be convertible to a binary string that does not exceed the length specified by the ''num'' value. </td></tr>
<tr><th>float</th>
<tr><th>num </th>
<td>An integer value. The number must be convertible to a binary string that does not exceed the length specified by the <var class="term">number</var> value. </td></tr>
<td>A non-zero numeric value that specifies the length of the binary string to be returned. Its value must be greater than 0 and less than 5. </td></tr>
 
<tr><th>[Signed=]bool </th>
<tr><th>number</th>
<td>This name-required argument (''''Signed'''') is a boolean value that indicates whether the method object integer is to be converted to a signed integer. If so, the resulting binary string will begin with a sign bit, and a two's complement conversion is performed.
<td>A non-zero numeric value that specifies the length in bytes of the binary string to be returned. Its value must be greater than 0 and less than 5.</td></tr>
''''Signed'''' is an optional argument that defaults to ''''False'''', which produces an unsigned conversion.</td></tr>
 
<tr><th><var>Signed</var></th>
<td>This is an optional, [[Notation conventions for methods#Named parameters|name required]], <var>[[Boolean enumeration]]</var> that indicates whether the method object integer is to be converted to a signed integer. If so, the resulting binary string will begin with a sign bit, and a two's complement conversion is performed.
<var>Signed</var> is an optional argument that defaults to <var>False</var>, which produces an unsigned conversion.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
*If the specified length of the returned binary string is greater than the binary value, the value is padded on the left with repetitions of the appropriate sign bit.
<ul><li>If the specified length of the returned binary string is greater than the binary value, the value is padded on the left with repetitions of the appropriate sign bit.
*If the specified length of the returned binary string is insufficient to contain the converted value and any necessary sign bit, the request is cancelled.
<li>If the specified length of the returned binary string is insufficient to contain the converted value and any necessary sign bit, the request is cancelled.
*The inverse of the IntegerToBinary method is [[BinaryToInteger (String function)|BinaryToInteger]].
<li><var>IntegerToBinary</var> is available as of <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 7.3.</ul>


==Examples==
==Examples==
The following statement displays an ''''a'''' character:
<ol><li>The following statement displays an '<code>a</code>' character:
    [[Intrinsic classes#printtext|printText]] {129:integerToBinary(1)}
<p class="code">[[PrintText statement|printText]] {129:integerToBinary(1)}
The following statement displays ''''??'''' because the resulting binary string is two non-displayable characters:
</p>
    printText {32769:integerToBinary(2)}
<li>The following statement displays '<code>??</code>' because the resulting binary string is two non-displayable characters:
To view the hex equivalents of the non-displayable characters above, you can use [[StringToHex (String function)|StringToHex]]. The following statement The displays ''''8001''''.
<p class="code">printText {32769:integerToBinary(2)}
    printText {32769:integerToBinary(2):stringToHex}
</p>
The following statement displays ''''FF7F'''':
<li>To view the hex equivalents of the non-displayable characters in examples above, you can use <var>[[StringToHex (String function)|StringToHex]]</var>. The following statement The displays '<code>8001</code>'.
    printText {-129:integerToBinary(2, signed=true):stringToHex}
<p class="code">printText {32769:integerToBinary(2):stringToHex}
The following statement displays ''''0081'''', a value padded with a positive sign bit:
</p>
    printText {129:integerToBinary(2, signed=true):stringToHex}
<li>The following statement displays '<code>FF7F</code>':
<p class="code">printText {-129:integerToBinary(2, signed=true):[[StringToHex (String function)|stringToHex]]}
</p>
<li>The following statement displays '<code>0081</code>, a value padded with a positive sign bit:
<p class="code">printText {129:integerToBinary(2, signed=true):stringToHex}
</p></ol>


==See also==
==See also==
[[List of intrinsic Float methods]]
<ul><li>The inverse of <var>IntegerToBinary</var> is <var>[[BinaryToInteger_(String_function)|BinaryToInteger]]</var>.</ul>
 
{{Template:Float:IntegerToBinary footer}}
[[Category:Float methods|IntegerToBinary function]]
[[Category: Intrinsic methods]]
 
 
 
<!--
<section begin=dpl_desc />
Convert to string with binary representation of integer value
<section end=dpl_desc />
-->

Latest revision as of 17:45, 2 November 2012

Convert an integer to a binary string (Float class)


The IntegerToBinary intrinsic function converts an integer to its binary string representation. Only integers that convert to a string no longer than four characters are allowed.

Syntax

%string = float:IntegerToBinary( number, [Signed= boolean])

Syntax terms

%string A string variable to receive the converted value of the method object float.
float An integer value. The number must be convertible to a binary string that does not exceed the length specified by the number value.
number A non-zero numeric value that specifies the length in bytes of the binary string to be returned. Its value must be greater than 0 and less than 5.
Signed This is an optional, name required, Boolean enumeration that indicates whether the method object integer is to be converted to a signed integer. If so, the resulting binary string will begin with a sign bit, and a two's complement conversion is performed. Signed is an optional argument that defaults to False, which produces an unsigned conversion.

Usage notes

  • If the specified length of the returned binary string is greater than the binary value, the value is padded on the left with repetitions of the appropriate sign bit.
  • If the specified length of the returned binary string is insufficient to contain the converted value and any necessary sign bit, the request is cancelled.
  • IntegerToBinary is available as of Sirius Mods Version 7.3.

Examples

  1. The following statement displays an 'a' character:

    printText {129:integerToBinary(1)}

  2. The following statement displays '??' because the resulting binary string is two non-displayable characters:

    printText {32769:integerToBinary(2)}

  3. To view the hex equivalents of the non-displayable characters in examples above, you can use StringToHex. The following statement The displays '8001'.

    printText {32769:integerToBinary(2):stringToHex}

  4. The following statement displays 'FF7F':

    printText {-129:integerToBinary(2, signed=true):stringToHex}

  5. The following statement displays '0081, a value padded with a positive sign bit:

    printText {129:integerToBinary(2, signed=true):stringToHex}

See also