The Hexadecimal filter converts an 8-bit binary value to its 2 character hexadecimal string representation. The hexadecimal character set consists of all hexadecimal characters representing their decimal value equivalent of numbers from zero to fifteen (0 - 15). All numbers from 0 to 15 are in 4 bits, and therefore a hexadecimal character can only represent any 4 bit decimal value.
Decimal Binary Hexadecimal Character 00 0 0 0 0 0x0 0 01 0 0 0 1 0x1 1 02 0 0 1 0 0x2 2 03 0 0 1 1 0x3 3 04 0 1 0 0 0x4 4 05 0 1 0 1 0x5 5 06 0 1 1 0 0x6 6 07 0 1 1 1 0x7 7 08 1 0 0 0 0x8 8 09 1 0 0 1 0x9 9 10 1 0 1 0 0xA A 11 1 0 1 1 0xB B 12 1 1 0 0 0xC C 13 1 1 0 1 0xD D 14 1 1 1 0 0xE E 15 1 1 1 1 0xF F
The conversion of an 8-bit byte proceeds as follows:
The above conversion is repeated for every bytes in the document. The resulting document should only contain an even number count of characters, and should only contain characters in the hexadecimal character set. For example when encoding the string "The 5 men" , the byte stream would be as follow (shaded):
Text | T | h | e | SP | 5 | SP | m | e | n |
Decimal | 84 | 104 | 101 | 32 | 53 | 32 | 109 | 101 | 110 |
Binary | 0101 0100 | 0110 1000 | 0110 0101 | 0010 0000 | 0011 0101 | 0010 0000 | 0110 1101 | 0110 0101 | 0110 1110 |
Hex Characters | "54" | "68" | "65" | "20" | "35" | "20" | "6D" | "65" | "6E" |
Byte Stream | 0x35 0x34 | 0x36 0x38 | 0x36 0x35 | 0x32 0x30 | 0x33 0x35 | 0x32 0x30 | 0x36 0x44 | 0x36 0x35 | 0x36 0x45 |
The resulting encoded text for "The 5 men" would be "5468652035204D654F".
The result is not case sensitive and the above result may also be
"5468652035204d654f". However, when both upper or lower case results
are decoded, they must return the original text in the correct case. Note
that for every byte in the original text, two bytes are created in the encoded
text. This 100 percent expansion rate is the biggest drawback in
using the hexadecimal encoding mechanism.