How many characters are in a GUID?

Using ASCII encoding, how many characters are present in the GUID?

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

+59
guid encoding
Mar 03 '09 at 18:59
source share
4 answers

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, followed by one group of 12 hexadecimal digits. The following GUID example displays a grouping of hexadecimal digits in a GUID: 6B29FC40-CA47-1067-B31D-00DD010662DA

From Wikipedia :

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

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

Thus, a typical hexadecimal encoding with curly braces contains only 38 characters.

-Adam

+111
Mar 03 '09 at 19:02
source share

TL; DR: Nope.

As Adam Davis said, Microsoft's style is the HEX encoding (with curly shapes and dashes to make it more readable), which can be displayed using a subset of ASCII characters (0-9 and AF), but this is not specifically ASCII encoding.

I think it's important to remember that Microsoft's GUID mapping style for Microsoft is just a GUID representation, which is actually a 16-byte integer value (as Micheal Trausch stated).

You can also represent it in different, more compact ways, converting bytes to another character set (e.g. ASCII).

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

This would not be very clear, because it would include whitespace (CR, space, tab, etc.) and other special characters, so that would make sense if you want to effectively keep the GUID in a non-human readable character format, for example , in a database that does not support GUIDs or quick bit mappings: http://en.wikipedia.org/wiki/Extended_ASCII

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

 7v26IM9P2kmVepd7ZxuXyQ== 

But, as Jeff Atwood claims on his website, you can also push the 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

+25
Jul 14 '10 at 15:49
source share

As Adam mentioned from the MSDN quote, UUIDs are 128-bit values. This means that they take 16 bytes of RAM to store the value. The text representation will take 32 bytes (two bytes for each byte) plus four hyphens plus two brackets if you want to include them; this is 38 bytes.

Just keep in mind that if you expose UUID users to your software users, they can provide UUIDs with or without parentheses. If you save the value anywhere, it is better to save it as a 16-byte binary representation. If you interact with other UUID implementations, you can use the basic text format for interoperability, as different implementations do different things in byte order while storing the binary UUID value.

+10
Mar 03 '09 at 19:06
source share

The length depends on the encoding. You can get the standard encodings and length using this snippet:

 public void Main() { var guid = Guid.Empty; Write(guid, "N"); // 32 characters Write(guid, "D"); // 36 characters (default) Write(guid, "B"); // 38 characters Write(guid, "P"); // 38 characters Write(guid, "X"); // 68 characters } private void Write(Guid guid, string format) { var guidString = guid.ToString(format); Console.WriteLine("{0}: {1} ({2} characters)", format, guidString, guidString.Length); } 

See Guid.ToString for more details:

+4
Mar 31 '14 at 15:14
source share



All Articles