Dev Helpers

Python / Standard library utilities

Format bytes using hexadecimal

Dev Helpers · September 11, 2025

Hexadecimal represents each byte with two digits. It is a convenient inspection format for payloads that are awkward to print.

Worked example

payload = bytes([0, 15, 255])
print(payload.hex(' '))

Result

00 0f ff

Implementation notes

A hexadecimal string is typically twice the byte length. A column sized for the binary payload may be too short for its printable representation.

Try it yourself

Include a zero byte and round-trip the result with bytes.fromhex.

Open the Python example →

Editorial date September 11, 2025 · Published December 6, 2026

Related articles

Run an async function

An async function call creates a coroutine. A top-level runner supplies the event loop that executes it.

Transpose a matrix

Transposing rows into columns assumes a decision about uneven rows. Ordinary zip stops at the shortest input.

Unpack with a remainder

Starred unpacking separates a fixed header from a variable-length tail. It still requires enough elements for the fixed positions.