System.SysUtils.IntToHex

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function IntToHex(Value: Int8): string;
function IntToHex(Value: UInt8): string;
function IntToHex(Value: Int16): string;
function IntToHex(Value: UInt16): string;
function IntToHex(Value: Int32): string;
function IntToHex(Value: UInt32): string;
function IntToHex(Value: Int64): string;
function IntToHex(Value: UInt64): string;
function IntToHex(Value: Integer; Digits: Integer): string;
function IntToHex(Value: Int64; Digits: Integer): string;
function IntToHex(Value: UInt64; Digits: Integer): string;

C++

extern DELPHI_PACKAGE System::UnicodeString __fastcall IntToHex(System::Int8 Value)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Returns the hex representation of an ordinal number.

IntToHex converts a number into a string containing the number's hexadecimal (base 16) representation.

There are two kinds of overloaded versions:

  1. First eight overloaded functions that have one parameter. The Value parameter to a hexadecimal string with a fixed and enough size of the Value parameter type. For example, IntToHex (Value: Int16) returns a 4 digits string, because Int16 has 2 bytes and 4 digits as the Hexadecimal representation. If the value has fewer digits from the type of Value, the resulting string is left-padded with zeros.
  2. Last three overloaded functions that have two parameters. The Value is the number to convert, the Digits indicate the minimum number of hexadecimal digits to return. If the value has fewer digits than the Digits parameter, the resulting string is left-padded with zeros.
Note: For double parameters, Value parameters that contain negative numbers are first expanded into a 32-bits Integer or a 64-bits Int64 (depending on the type of the variable or the size of the constant) and then converted into a hexadecimal notation. Therefore, regardless of the digit specification, the result returned is an 8-digit string for integer or a 16-digit string for Int64.

To avoid this, use a single parameter version and cast to the ordinal type with the required number of digits. For example:

IntToHex( -42, 2 ); // Result string is 'FFFFFFD6'
IntToHex( int8( -42) ); // Result string is 'D6'
IntToHex( int16( -42) ); //  Result string is 'FFD6'

See Also

Code Examples