binascii hexlify Formats Bytes and b85 Packs Text
Format binary digests with delimiter support via binascii.hexlify and pack bytes compactly with base64.b85encode compared against Base64 overhead.
Code
import base64
import binascii
mac_bytes = bytes.fromhex("a45e60c219f0")
# binascii.hexlify supports sep (Python 3.8+) to format byte groups directly
colon_mac = binascii.hexlify(mac_bytes, sep=":").decode("ascii")
roundtrip = binascii.unhexlify(colon_mac.replace(":", ""))
print("mac:", colon_mac, "| roundtrip ok:", roundtrip == mac_bytes)
# Base85 uses a 5:4 expansion (25% overhead) vs Base64's 4:3 (33% overhead)
payload = b"frame-header-0123456789-checksum"
b64 = base64.b64encode(payload)
b85 = base64.b85encode(payload)
print(f"raw={len(payload)}B b64={len(b64)}B b85={len(b85)}B")
print("b85 sample:", b85.decode("ascii"), "| decoded ok:", base64.b85decode(b85) == payload)Output
Captured from a sandboxed run of this snippet in the build pipeline.
mac: a4:5e:60:c2:19:f0 | roundtrip ok: True
raw=32B b64=44B b85=40B
b85 sample: W^!R|Wi4oBVPs`;Eif@MGc+|eH#j*hV`yb#YjbsN | decoded ok: TrueBehavior overview — binascii hexlify Formats Bytes and b85 Packs Text
Top-level bindings mac_bytes, colon_mac, roundtrip, payload hold the demo state — nothing sits inside a function scope.
What to watch for
- The whole dependency story is the language version itself.
Using it
The demo output is labeled (mac:, raw=, b85 sample:); each label names the call that printed it.
Interactive Tools for This Topic
ASCII Table ReferenceLook up any ASCII code point 0-127 by decimal, hex, or character and see the binary, octal, and control-name view.ASCII85 EncoderEncode and decode ASCII85 (Base85), the Adobe variant with z zero-compression, handling arbitrary bytes and Unicode.Base32 Encoder & DecoderEncode and decode RFC 4648 Base32 with padding, fully UTF-8 safe so Unicode text round-trips without corruption. Nothing leaves your browser.Base45 Encoder and DecoderEncode and decode text with the Base45 alphabet defined in RFC 9285, with UTF-8 support, padding-free output, and clear validation errors.
FAQ
- What has to be installed first?
- Nothing — the runtime itself provides everything the code touches. Every import resolves inside the standard library — `base64`, `binascii`. Its state lives in module-level bindings: `mac_bytes`, `colon_mac`, `roundtrip`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.