IntegerToBinary (Float function): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 17: | Line 17: | ||
<tr><th>[Signed=]bool</th> | <tr><th>[Signed=]bool</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>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. | ||
<p class="code">''''Signed'''' is an optional argument that defaults to ''''False'''', which produces an unsigned conversion.</td></tr> | |||
</p> | |||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
Line 26: | Line 27: | ||
==Examples== | ==Examples== | ||
The following statement displays an ''''a'''' character: | The following statement displays an ''''a'''' character: | ||
<p class="code">[[Intrinsic classes#printtext|printText]] {129:integerToBinary(1)} | |||
</p> | |||
The following statement displays ''''??'''' because the resulting binary string is two non-displayable characters: | The following statement displays ''''??'''' because the resulting binary string is two non-displayable characters: | ||
<p class="code">printText {32769:integerToBinary(2)} | |||
</p> | |||
To view the hex equivalents of the non-displayable characters above, you can use [[StringToHex (String function)|StringToHex]]. The following statement The displays ''''8001''''. | 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):stringToHex} | |||
</p> | |||
The following statement displays ''''FF7F'''': | The following statement displays ''''FF7F'''': | ||
<p class="code">printText {-129:integerToBinary(2, signed=true):stringToHex} | |||
</p> | |||
The following statement displays ''''0081'''', a value padded with a positive sign bit: | The following statement displays ''''0081'''', a value padded with a positive sign bit: | ||
<p class="code">printText {129:integerToBinary(2, signed=true):stringToHex} | |||
</p> | |||
==See also== | ==See also== | ||
[[List of intrinsic Float methods]] | [[List of intrinsic Float methods]] |
Revision as of 15:50, 20 January 2011
Convert an integer to a binary string (Float class)
This intrinsic function converts an integer to its binary string representation.
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
%string = float:IntegerToBinary( number, [Signed= boolean])
Syntax terms
%str | A string variable to receive the converted value of the method object number. |
---|---|
number | An integer value. The number must be convertible to a binary string that does not exceed the length specified by the num value. |
num | 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. |
[Signed=]bool | 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.
'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.
- The inverse of the IntegerToBinary method is BinaryToInteger.
Examples
The following statement displays an 'a' character:
printText {129:integerToBinary(1)}
The following statement displays '??' because the resulting binary string is two non-displayable characters:
printText {32769:integerToBinary(2)}
To view the hex equivalents of the non-displayable characters above, you can use StringToHex. The following statement The displays '8001'.
printText {32769:integerToBinary(2):stringToHex}
The following statement displays 'FF7F':
printText {-129:integerToBinary(2, signed=true):stringToHex}
The following statement displays '0081', a value padded with a positive sign bit:
printText {129:integerToBinary(2, signed=true):stringToHex}
See also
List of intrinsic Float methods