tohex()

Applies to: ✅ Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

Converts input to a hexadecimal string.

Syntax

tohex(value, [, minLength ])

Learn more about syntax conventions.

Parameters

Name Type Required Description
value int or long ✔️ The value that is converted to a hex string.
minLength int The value representing the number of leading characters to include in the output. Values between 1 and 16 are supported. Values greater than 16 are truncated to 16. If the string is longer than minLength without leading characters, then minLength is effectively ignored. Negative numbers are only represented at minimum by their underlying data size, so for an integer (32-bit) the minLength is at minimum 8, for a long (64-bit) it's at minimum 16.

Returns

If conversion is successful, result is a string value. If conversion isn't successful, result is null.

Example

The following example checks whether the tohex() integer conversion results in the expected hexadecimal value.

print
    tohex(256) == '100',
    tohex(-256) == 'ffffffffffffff00', // 64-bit 2's complement of -256
    tohex(toint(-256), 8) == 'ffffff00', // 32-bit 2's complement of -256
    tohex(256, 8) == '00000100',
    tohex(256, 2) == '100' // Exceeds min length of 2, so min length is ignored.

Output

print_0 print_1 print_2 print_3 print_04
true true true true true