Module eco.encoding.hex

Hex encoding/decoding utilities.

This module provides helpers to encode raw bytes into lowercase hexadecimal strings, decode hex strings back into raw bytes, and format a hexdump similar to hexdump -C.

Functions

encode (bin[, sep='']) Encode bytes to a hexadecimal string.
decode (s) Decode a hexadecimal string into bytes.
dump (data) Format a hexdump of the given data.


Functions

encode (bin[, sep=''])
Encode bytes to a hexadecimal string.

Parameters:

  • bin string Input bytes.
  • sep string Optional separator inserted between bytes. (default '')

Returns:

    string Lowercase hexadecimal string.
decode (s)
Decode a hexadecimal string into bytes.

On malformed input, returns nil, 'input is malformed'.

Parameters:

Returns:

    string out Decoded bytes.

Or

  1. nil On malformed input.
  2. string Error message.
dump (data)
Format a hexdump of the given data.

The format matches the output of hexdump -C.

Parameters:

Returns:

    string Dump string (contains newlines).

Usage:

    local hex = require 'eco.encoding.hex'
    print(hex.dump('hello'))
generated by LDoc 1.5.0 Last updated 2026-04-09 14:48:22