How to compress an hexadecimal number into a short string?
<p>I have an hexadecimal number of unknown length and I would like to convert it into a string as short as possible. And later be able to convert the new string back to the original number.</p>

<p>Since each digit is on only 4 bits, I was thinking to convert the number into a UFT-16 or UFT-32 string. That would create a short string with weird characters.</p>

<p>Hypothetical example: 0x874FAB41900C -> "ÚΔЂ" -> 0x874FAB41900C.</p>

<p>So what I'm looking for is two Javascript functions like this:</p>

<pre><code>function hexToString(hex) {
    for (var i=0; i &lt; hex.length; i++) {
        // convert the digits into UFT-16
    }

    return string;
}

function stringToHex(string) {
    for (var i=0; i &lt; string.length; i++) {
        // convert the char back into hex values
    }

    return hex;
}
</code></pre>

<p>Any idea how to do this?</p>