IntegerToHex (Float function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (match syntax diagram to revised template; fix tags and links)
m (printtext)
Line 26: Line 26:
==Examples==
==Examples==
<ol><li>The following statement displays '<code>00000000</code>':
<ol><li>The following statement displays '<code>00000000</code>':
<p class="code">printText {0:integerToHex(4)}
<p class="code">[[PrintText statement|printText]] {0:integerToHex(4)}
</p>
</p>
<li>The following statement displays '<code>0000000A</code>':
<li>The following statement displays '<code>0000000A</code>':
Line 39: Line 39:


==See also==
==See also==
<ul><li>The inverse of the <var>IntegerToHex</var> method is <var>[[HexToInteger (String function)|HexToInteger]]</var>.
<ul><li>The inverse of the <var>IntegerToHex</var> method is <var>[[HexToInteger (String function)|HexToInteger]]</var>.</ul>
<li>For details of the <var>printtext</var> statement, please see <var>[[Intrinsic classes#printtext|printText]]</var>.</ul>
{{Template:Float:IntegerToHex footer}}
{{Template:Float:IntegerToHex footer}}

Revision as of 11:41, 22 February 2011

Convert an integer to a hexadecimal string (Float class)


The IntegerToHex intrinsic function converts an integer to its hexadecimal string representation. Only integers that convert to four hex bytes or less (so a maximum output string length of eight) are allowed.

Syntax

%string = float:IntegerToHex( 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 hex string that does not exceed the output size specified by the number value (plus a sign bit, if that is indicated).

If number is a negative value, you must specify 'Signed=true'.

number A non-zero numeric value that specifies the number of hex bytes to be returned. Its value must be greater than 0 and less than 5.
Signed This is an optional, but nameRequired, boolean value that indicates whether the method object number is to be converted to signed output or not. If Signed=True, the resulting hex string will begin with a sign bit '00' or 'FF'), and a two's complement conversion is performed.

Signed defaults to 'False', which produces an unsigned conversion.

Usage notes

  • If the specified size of the returned hex value is greater than the hex value, the returned value is padded on the left with repetitions of the appropriate sign bit.
  • If the specified size of the returned hex value is insufficient to contain the converted value and any necessary sign bit, the request is cancelled.
  • IntegerToHex is available as of "Sirius Mods" Version 7.5.

Examples

  1. The following statement displays '00000000':

    printText {0:integerToHex(4)}

  2. The following statement displays '0000000A':

    printText {10:integerToHex(4)}

  3. The following statement displays 'FF':

    printText {255:integerToHex(1)}

  4. The following statement displays 'FF':

    printText {-1:integerToHex(1, signed=true)}

See also