Possible Duplicate:
Compress 21 Alphanumeric Characters in to 16 Bytes
I have 8 numbers
is there a way to convert it to a string which length is 4?
for instance:
input 12345678
output AB2D
the conversion should be able to convert back exactly.
I tried to convert it to 32 Hex, but it still has 5 numbers, and I can’t use 0 1 O I in the final string. Is there any good suggestions? btw, only upper case letters could be used.
It comes down to maths. If you need to be able to represent 10^8 possible numbers and you need to use 4 symbols, each symbol must allow 100 different values.
10^8^(1/4)You can do this using an 8-bit byte but your requirement ofonly upper case letters could be used.suggests your options are rather limited. You have to determine 100 letters you can use or you have to make assumptions about the range of numbers you can have.BTW: If you can use non-ASCII upper case characters you don’t have a problem. 😉
There are 26 upper case ASCII characters, 30 upper case characters between 128 and 255 and 10 digits so you would have to use 34 symbols as well. If you can use Unicode, there are 1898 upper-case and digit Unicode characters.
There is 163 non lower-case characters between
(char) 32and(char) 255and if you can use most of these you can do it.A hand picked list of possible characters will be a better choice but this is an example.
prints using a character which is non-printable in this font 🙁