IacStdFunctions
Hex Functions
Standard library functions for hexadecimal encoding and decoding
encode_hex
encode_hex encodes a buffer or string as a hexadecimal string with 0x prefix.
Inputs
| Name | Type | Description |
|---|---|---|
value | buffer, string, addon | The buffer or string to encode. Strings starting with '0x' are decoded as hex; otherwise, raw UTF-8 bytes are used. |
Output
| Name | Type | Description |
|---|---|---|
value | string | The input in its hexadecimal representation with 0x prefix |
output "encoded_hex" {
value = encode_hex("hello, world")
}
// > encoded_hex: 0x68656c6c6f2c20776f726c64decode_hex
decode_hex decodes a hexadecimal string and returns the result as a buffer.
Inputs
| Name | Type | Description |
|---|---|---|
hex_string | string | The hex string to decode (with or without 0x prefix) |
Output
| Name | Type | Description |
|---|---|---|
value | buffer | The decoded hex string as a buffer |
output "decoded_hex" {
value = decode_hex("0x68656c6c6f2c20776f726c64")
}
// > decoded_hex: 0x68656c6c6f2c20776f726c64