binary.unhex()
Decodes hexadecimal byte pairs.
Signature
binary.unhex(data)
Parameters
Text or packed span containing ASCII digits, with upper or lower case A–F.
Returns
Packed u8 bytes.
Behavior
Accepts empty input.
Errors
Odd length, invalid digit or unsupported input.
Example
use binary
assert(binary.text(binary.unhex('41')) == 'A')
Decode two hex digits
Give unhex hexadecimal text when you need the underlying bytes.
use binary
print(binary.text(binary.unhex('41')))
A
The hex pair 41 represents the byte for A.
Decode a packed ASCII input
Use a byte buffer when the hexadecimal digits came from binary input.
use binary
text_bytes = binary.utf8('41')
print(binary.text(binary.unhex(text_bytes)))
A
unhex reads the ASCII digits from the buffer and returns the same decoded byte.