Odd length."414" has three characters—not complete pairs.
Failure.hex2bin() returns false (and warns).
Strict check. Use === false so empty binary is not confused with failure.
Fix. Pad or reject incomplete hex before decoding.
Frequently Asked Questions
hex2bin() decodes a hexadecimal string into its original binary form (a PHP string of raw bytes). Each pair of hex digits becomes one byte—for example, "48656c6c6f" becomes "Hello".
string|false hex2bin(string $string). Pass a hex-encoded string with an even number of characters (0–9, a–f, A–F). Returns the decoded binary string on success, or false on failure.
No. hex2bin() decodes hex-encoded byte data, not numeric radix conversion. To turn the number 0xff into binary digits, use base_convert('ff', 16, 2)—not hex2bin().
hex2bin() returns false and PHP emits a warning, because each byte needs exactly two hex digits. An input like "414" (three characters) is invalid.
They are inverse operations. bin2hex() encodes raw bytes as hex; hex2bin() decodes hex back to bytes. A round-trip restores the original string.