IntegerToBinary (Float function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (printtext and friends)
Line 13: Line 13:
<tr><th>number</th>
<tr><th>number</th>
<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>
<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</th>
<tr><th><var>Signed</var></th>
<td>This is an optional, but <var class="term">nameRequired</var>, <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.
<td>This is an optional, but <var class="term">nameRequired</var>, <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 class="term">Signed</var> is an optional argument that defaults to <var class="term">False</var>, which produces an unsigned conversion.</td></tr>
<var class="term">Signed</var> is an optional argument that defaults to <var class="term">False</var>, which produces an unsigned conversion.</td></tr>

Revision as of 15:23, 5 April 2011

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 of the binary string to be returned. Its value must be greater than 0 and less than 5.
Signed This is an optional, but nameRequired, 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