IntegerToHex (Float function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 9: Line 9:
{{Template:Float:IntegerToHex syntax}}
{{Template:Float:IntegerToHex syntax}}
===Syntax terms===
===Syntax terms===
<dl>
<table class="syntaxTable">
<dt>%str
<tr><th>%str </th>
<dd>A string variable to receive the converted value of the method object number.
<td>A string variable to receive the converted value of the method object number. </td></tr>
<dt>number
<tr><th>number </th>
<dd>An integer value.
<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).
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).
If ''number'' is a negative value, you must specify ''''Signed=true''''. </td></tr>
 
<tr><th>num </th>
If ''number'' is a negative value, you must specify ''''Signed=true''''.
<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>
<dt>num
<tr><th>Signed=bool </th>
<dd>A non-zero numeric value that specifies the number of hex bytes to be returned.
<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.
Its value must be greater than 0 and less than 5.
Signed is an optional argument that defaults to ''''False'''', which produces an unsigned conversion.</td></tr>
<dt>Signed=bool
</table>
<dd>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.
 
Signed is an optional argument that defaults to ''''False'''', which produces an unsigned conversion.
</dl>
==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.
*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.

Revision as of 13:44, 19 January 2011

Convert an integer to a hexadecimal string (Float class)


This 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.

The IntegerToHex function is available as of version 7.5 of the Sirius Mods.

Syntax

%string = float:IntegerToHex( 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 hex string that does not exceed the output size specified by the num value (plus a sign bit, if that is indicated). If number is a negative value, you must specify 'Signed=true'.
num 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=bool 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. Signed is an optional argument that 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.
  • The inverse of the IntegerToHex method is HexToInteger.

Examples

The following statement displays '00000000':

   printText {0:integerToHex(4)}

The following statement displays '0000000A':

   printText {10:integerToHex(4)}

The following statement displays 'FF':

   printText {255:integerToHex(1)}

The following statement displays 'FF':

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

See also

List of intrinsic Float methods