IntegerToHex (Float function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 44: Line 44:
==See also==
==See also==
{{Template:Float:IntegerToHex footer}}
{{Template:Float:IntegerToHex footer}}
<!--
<section begin=dpl_desc />
Convert to string with hexadecimal representation of integer value
<section end=dpl_desc />
-->

Revision as of 21:27, 26 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