Reputation: 205
I have some 16 character hex strings like this:
B5A43BC5BDCEEFC6
2C7C27F05A488897
1514F4EC47C2EBF6
D91ED66BC999EB64
I want to shorten them and have the shortened string only contain upper case letters.
DeflateStream and GZipStream just increase the length.
Anyone can help me shorten these 16 characters hex string to 6 characters or fewer?
Alternatively, shortening a 32 character hex string to 12 characters or fewer is okay.
Upvotes: 0
Views: 4487
Reputation: 8805
Unless there is some redundancy in your 16 hexadecimal character input, what you are asking is mathematically impossible. You can prove this by examining the entropy of your inputs.
16^16 = 18446744073709551616 ≈ 1.84x10^19 possible values.
26^6 = 308915776 ≈ 3.09x10^8 possible values.
To guarantee that you can represent every one of your 16 hexadecimal characters, you need 14 upper (or lower) case letters.
13 characters isn't enough:
26^13 = 2481152873203736575 ≈ 2.48x10^18 possible values.
26^14 = 64509974703297150976 ≈ 6.45x10^19 possible values.
1626^6 = 18480905552168525376 ≈ 1.849x10^19 possible values.
Shortening 32 hexadecimal characters to 12 or fewer upper (or lower) case characters is impossible by the same logic. Without redundancy, you can't guarantee that you can shorten any arbitrary 16 (or 32) hexadecimal characters into 6 (or 12) upper (or lower) case characters.
Upvotes: 2
Reputation: 7919
You can convert hexadecimal number to a higher base like sexagesimal:
Quickest way to convert a base 10 number to any base in .NET?
Upvotes: 0