Seeking method to represent GUID in most concise displayable format

  • Thread starter Thread starter Joseph Geretz
  • Start date Start date
J

Joseph Geretz

A GUID requires 32 digits to display its value in Hex - e.g.
d3a161b95384475da608061051f27b06.

How many 'digits' would it require to display the same value in Base-64
using the following characters?

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+*

Any idea on how I'd go about making the conversion? I'm looking for the
ability to encode this information in the most concise possible displayable
format so that a transaction would be identified by a code such as
5rHrH+tt0*edt9, rather than d3a161b95384475da608061051f27b06.

(BTW, I've already seen
http://www.codeproject.com/KB/string/Compact_Guid_class.aspx. The algorithm
presented there simply does not work!)

Thanks for your advice!

- Joseph Geretz -
 
Joseph said:
A GUID requires 32 digits to display its value in Hex - e.g.
d3a161b95384475da608061051f27b06.

How many 'digits' would it require to display the same value in Base-64
using the following characters?

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+*

A GUID is 16 bytes.

Base64 uses 4/3 of original space.

16*4/3 = 22 (rounded up)
Any idea on how I'd go about making the conversion?

The Convert class has methods to convert between byte[] and
a string with base64.

I can not see any reason why not to use that.

Arne
 
Joseph said:
A GUID requires 32 digits to display its value in Hex - e.g.
d3a161b95384475da608061051f27b06.

How many 'digits' would it require to display the same value in Base-64
using the following characters?

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+*

First off, I assume you are looking for an ASCII representation . . .

It doesn't matter which characters they are. Your GUID contains 128 bits of
information. To represent it with 4-bit nybbles requires 128/4 or 32 nybbles.
With 6-bit nybbles you would need CEILING(128/6) nybbles, or 22.
Any idea on how I'd go about making the conversion? I'm looking for the
ability to encode this information in the most concise possible displayable
format so that a transaction would be identified by a code such as
5rHrH+tt0*edt9, rather than d3a161b95384475da608061051f27b06.

To get it THAT short (the 14 nybbles in your example) each nybble would have to
encode 10 bits, since 128/14 is between 9 and 10. This would require a
"character set" with 1024 distinct printable characters. Good luck with that.
(BTW, I've already seen
http://www.codeproject.com/KB/string/Compact_Guid_class.aspx. The algorithm
presented there simply does not work!)

Dunno how it's done there, it but the idea is straightforward enough. Starting
with your 128-bit unsigned integer, shift 6 bits at at a time off the right end
and use them as an index into your character array to pick the character which
represents your nybble. Conversion back the other way is trickier because your
chosen character set is not a simple 64-element contiguous subset of the ASCII
character set. Indexed lookup from character to 6-bit value may be your best
bet there.

HTH,
-rick-
 
Back
Top