IntegerToHex (Float function): Difference between revisions

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


This [[Intrinsic classes|intrinsic]] function converts an integer to its hexadecimal string representation.
The <var>IntegerToHex</var> [[Intrinsic classes|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.
Only integers that convert to four hex bytes or less
(so a maximum output string length of eight) are allowed.


The IntegerToHex function is available as of version 7.5 of the <var class=product>Sirius Mods</var>.
==Syntax==
==Syntax==
{{Template:Float:IntegerToHex syntax}}
{{Template:Float:IntegerToHex 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 hex string that does not exceed the output size specified by the ''num'' value (plus a sign bit, if that is indicated).
<tr><th>float</th>
If ''number'' is a negative value, you must specify ''''Signed=true''''. </td></tr>
<td>An integer value. The number must be convertible to a hex string that does not exceed the output size specified by the <var class="term">number</var> value (plus a sign bit, if that is indicated).
<tr><th>num </th>
<p>If <var class="term">number</var> is a negative value, you must specify <code>Signed=true</code>. </p></td></tr>
<td>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. </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 number is to be converted to signed output. If so, the resulting hex string will begin with a sign bit ''''00'''' or ''''FF''''), and a two's complement conversion is performed.
<td>A non-zero numeric value that specifies the number of bytes to be returned in hexadecimal format (two characters for each byte). The value must not be greater than 4.</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</var> value that indicates whether the method object number is to be converted to signed output or not. If <code>Signed=True</code>, the resulting hex string will begin with a sign bit '<code>00</code>' or '<code>FF</code>'), and a two's complement conversion is performed.
<p>
<var>Signed</var> defaults to <var>False</var>, which produces an unsigned conversion.</p></td></tr>
</table>
</table>
==Usage notes==
==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.
<ul>
*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.
<li>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.
*The inverse of the IntegerToHex method is [[HexToInteger (String function)|HexToInteger]].
 
<li>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.
 
<li><var>IntegerToHex</var> is available as of <var class="product">Sirius Mods</var> Version 7.5.
</ul>


==Examples==
==Examples==
The following statement displays ''''00000000'''':
<ol>
    [[Intrinsic classes#printtext|printText]] {0:integerToHex(4)}
<li>The following statement displays <code>00000000</code>:
The following statement displays ''''0000000A'''':
<p class="code">[[PrintText statement|printText]] {0:integerToHex(4)}
    printText {10:integerToHex(4)}
</p>
The following statement displays ''''FF'''':
    printText {255:integerToHex(1)}
The following statement displays ''''FF'''':
    printText {-1:integerToHex(1, signed=true)}


==See also==
<li>The following statement displays <code>0000000A</code>:
[[List of intrinsic Float methods]]
<p class="code">printText {10:integerToHex(4)}
[[Category:Float methods|IntegerToHex function]]
</p>
[[Category: Intrinsic methods]]
 
<li>The following statement displays <code>FF</code>:
<p class="code">printText {255:integerToHex(1)}
</p>


<li>The following statement displays <code>FF</code>:
<p class="code">printText {-1:integerToHex(1, signed=true)}
</p>
</ol>


==See also==
<ul>
<li>The inverse of the <var>IntegerToHex</var> method is <var>[[HexToInteger (String function)|HexToInteger]]</var>.
</ul>


<!--
{{Template:Float:IntegerToHex footer}}
<section begin=dpl_desc />
Convert to string with hexadecimal representation of integer value
<section end=dpl_desc />
-->

Latest revision as of 17:52, 2 November 2012

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 bytes to be returned in hexadecimal format (two characters for each byte). The value must not be greater than 4.
Signed This is an optional, name required, 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