IntToHex
function IntToHex(v: Int64; d: Integer): string;
Example
procedure ScriptEvent(var Value: variant);
begin
Value := IntToHex(4660, 8); // '00001234'
end;
Usage
IntToHex formats an Int64 as uppercase hexadecimal text with a requested minimum digit count.
Parameters
| Name | Type | Description |
|---|---|---|
v | Int64 | Signed 64-bit value to format. |
d | Integer | Minimum number of hexadecimal characters. It is not an exact-width or truncation argument. |
Returns
Uppercase hexadecimal digits with at least d characters when the requested width exceeds the natural representation. No $ or 0x prefix is included.
Errors
String length/range and allocation failures can propagate for invalid or excessive requested widths. Every valid Int64 has a hexadecimal representation.
Usage notes
For a fixed-width integration field, validate that the natural output length does not exceed the field. This function will not signal truncation because it never truncates. When converting the result back with HexToInt, remember that a 16-digit high-bit-set pattern returns a negative signed value.
Additional Technical Info
IntToHex formats a signed 64-bit integer as uppercase hexadecimal text. Digits specifies the minimum output width: smaller magnitudes are left-padded with zeroes, but larger representations are never truncated.
The example is source-reviewed and is not executed by the documentation workflow.
Implementation
The Velox wrapper calls the installed System.SysUtils.IntToHex(Int64, Integer) overload. Delphi treats the signed value as its 64-bit ordinal bit pattern and formats it using uppercase digits.
Edge cases and quirks
Digitsis a minimum.IntToHex($1234, 2)returns1234, not34.- A negative
Int64returns all 16 hexadecimal digits of its two's-complement representation, even whenDigitsis smaller. For example,IntToHex(-1, 2)returnsFFFFFFFFFFFFFFFF. - Zero has a natural representation of
0; a larger positive width adds leading zeroes. - A non-positive requested width does not remove required digits. It should not be used to request an empty result.
- Very large widths allocate and fill a correspondingly large string. Apply a width limit to external values.
Side effects
None outside result-string allocation.
Performance and concurrency
Numeric conversion is bounded by 16 natural digits, plus work proportional to any requested zero padding. The routine has no shared mutable state or locale dependency.
Related entries
HexToIntparses unprefixed hexadecimal digits into a signedInt64.BinToHexinvokes this formatting rule for each Variant-array element with a minimum width of two.IntToStrreturns decimal rather than hexadecimal text.
External references
- Embarcadero
System.SysUtils.IntToHex- documents the exact overload, minimum width and negative-value expansion. - Free Pascal
IntToHex- compatible minimum-width and non-truncation reference; Velox executes Delphi's implementation.