How many characters are there in a GUID?

Using ASCII encoding, how many characters are there in a GUID?

I'm interested in the Microsoft style, which includes the curly brackets and dashes.


Solution 1:

From MSDN:

A GUID is a 128-bit value consisting of one group of 8 hexadecimal digits, followed by three groups of 4 hexadecimal digits each, followed by one group of 12 hexadecimal digits. The following example GUID shows the groupings of hexadecimal digits in a GUID: 6B29FC40-CA47-1067-B31D-00DD010662DA

From Wikipedia:

Often braces are added to enclose the above format, as such:

{3F2504E0-4F89-11D3-9A0C-0305E82C3301}

So a total of 38 characters in the typical hexadecimal encoding with curly braces.

-Adam

Solution 2:

TL;DR: None.

As Adam Davis stated, the Microsoft style is HEX encoding (with braces and dashes to make it more readable) that can be displayed using a subset of ASCII characters (0-9 and A-F), but this is not specifically ASCII encoding.

I guess it's important to remember that the microsoft style of displaying GUID's is only a representation of a GUID, which is actually a 16 byte integral value (as Micheal Trausch stated).

You can also present it in different, more compact ways by converting the bytes into a different character set (like ASCII).

Theoretically you can display each byte as an extended ASCII character (255 characters), which would allow you to save a GUID as a 16 character length string.

It wouldn't be very readable though because it would include whitespace characters (CR, space, tab, etc) and other special characters, so this would only make sense if you want to efficiently save a GUID in a non-human readable character format, for example in in a database that doesn't natively support GUID's or fast matching of small binary values: http://en.wikipedia.org/wiki/Extended_ASCII

IMHO the most readable way to display a GUID more compact would be to use Base64 encoding, which allows you to save it in a string with a length of 22 characters, and would make it look like this:

7v26IM9P2kmVepd7ZxuXyQ==

But as Jeff Atwood states on his site, you can also push a GUID into an ASCII85 encoded string with 20 characters:

[Rb*hlkkXVW+q4s(YSF0

For more inspiration, see: http://www.codinghorror.com/blog/2005/10/equipping-our-ascii-armor.html