3

For example is it possible to compress

002e3483bbdc11ddaae0754822a559f6 into something that just takes at most 30 characters.

5
  • use the ascii equivalent? 002e3483bbdc11ddaae0754822a559f6 is ?.4???????uH"?Y? dolcevie.com/js/converter.html
    – SeanC
    Feb 8, 2013 at 14:33
  • Is your question - compress 32 hex numbers into 30 hex numbers? Feb 8, 2013 at 15:07
  • The string is 32 characters long.The only possible characters are 0123456789abcdef Feb 8, 2013 at 15:17
  • I know what hex is, I'm asking whether the output also needs to be hex. Feb 8, 2013 at 15:20
  • No. It just needs to be 30 or less characters. Ideally readable onces. The acscii solution is also valid. Feb 8, 2013 at 15:42

3 Answers 3

4

Yes, you can convert it to a base-32 number so the greatest 32 characters hex number i.e. ffffffffffffffffffffffffffffffff is equivalent to 80000000000000000000000000 in base-32 that only has 26 characters, also note that in base-32 you will end with a string containing only this characters: 123456789ABCDEFGHIJKLMNOPQRSTUV

For example: 002e3483bbdc11ddaae0754822a559f6 is 5OQ87EUS27F0000000000000 in base-32

3
  • How can I convert to base 32. Do you have an online calculator. I want to verify this myself. Feb 8, 2013 at 15:23
  • Sure, check this link unitconversion.org/numbers/…, you should google for your language specific implementation Feb 8, 2013 at 15:46
  • This method of conversion is limited to arithmetic conversion. While it works with "small" numbers it still requires 128bit arithmetic for OP's requirements and would be unusable for larger hex data. Also this could easily be confused with the Base32 binary to hex conversion, which could be used after conversion to binary except it is 8-byte padded so you would have to strip then reconstruct the padding. Jul 8, 2021 at 5:44
1

If your question is to compress 32 hex numbers into 30 hex numbers.

This is impossible to occur for all test cases, since, if it were possible, multiple 32-length hex strings would have to compress to the same 30-length hex string, thus you wouldn't know which one it was (the pigeonhole principle).

A less proof-y proof - you'd be able to repeatedly invoke the process on any size file to get down to a single 30-length hex string, which doesn't make a whole lot of sense.

Here is a article I just found. Wikipedia says something similar.

1
0

Convert hex to binary then use something like base64 or any other encoding scheme, see Binary-to-text encoding (Wikipedia). This has the advantage of not requiring 128bit arithmetic like the suggested base32 solution.

Conversion to base64 and back:

$ echo 002e3483bbdc11ddaae0754822a559f6 |xxd -r -ps |openssl base64 -e |tee >(openssl base64 -d |xxd -ps)
AC40g7vcEd2q4HVIIqVZ9g==
002e3483bbdc11ddaae0754822a559f6

Cut the line starting from |tee to get only the encoded output. In most programing languages you will have core or external libraries to do hex to binary conversion and base64 encoding.

NB: Conversion to base32 would also be possible but the base32 binary to text encoding requires 8-bytes padding, so you would have to trim it then re-add the pads (=) on decode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.