tohex
This page explains how to use the tohex function in APL.
Use the tohex function to convert integer or long values to hexadecimal string representation. This is helpful when you need to display numeric values in hexadecimal format, work with memory addresses, or convert identifiers to hex format for compatibility with other systems.
You typically use tohex when working with numeric identifiers, memory addresses, or when you need hexadecimal representation for debugging, logging, or system integration purposes.
Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
| value | int | The integer or long value to convert to hexadecimal string. |
| minLength | int | Optional. Minimum length of the resulting hex string. Default is 0. |
Returns
If conversion is successful, the result is a string value representing the hexadecimal representation. If conversion isn't successful, the result is null.
Example
Convert HTTP status codes to hexadecimal format for display or integration with systems that use hex values.
Query
Output
| _time | uri | status | status_hex |
|---|---|---|---|
| Jun 24, 09:28:10 | /api/users | 404 | 00000194 |
This example converts the status field to an integer with toint because tohex only accepts integer input, and then formats it as a hexadecimal string padded to 8 characters.
List of related functions
- toint: Converts input to integer. Use
tointfor smaller integers before converting to hex. - tostring: Converts input to string. Use
tostringfor general string conversion, andtohexspecifically for hexadecimal representation.