Bits, not hex
Focusing on hexadecimal digits is confusing you.
A UUID is not made of hex. A UUID is made of 128 bits.
Humans would resent reading a series of 128 bits presented as a long string of 1
and 0
characters. So for the benefit of reading and writing by humans, we present the 128-bits in hex.
Always keep in mind that when you see the series of 36 hex characters with hyphens, you are not looking at a UUID. You are looking at some text generated to represent the 128-bits of that are actually in the UUID.
Version & Variant
The first special meaning you mention, the “version” of UUID, is recorded using 4 bits. See section 4.1.3 of your linked spec.
The second special meaning you indicate is the “variant”. This value takes 1-3 bits. This See section 4.1.1 of your linked spec.
A hex character represents 4 bits (half an octet).
- The Version number, being 4 bits, takes an entire a single hex character to itself.
- Version 4 specifically uses the bits
01 00
which in hex is 4
as it is too in decimal (base 10) numbers.
- The Variant, being 1-3 bits, does not take an entire hex character.
- Outside the Microsoft world of GUIDs, the rest of the industry nowadays uses two bits:
10
, for a decimal value of 2, as the variant. This pair of bits lands in the most significant bits of octet # 8. That octet looks like this, where ‘n’ means 0 or 1: 10 nn nn nn
. A pair of hex characters represent each half of that octet. So your 17th hex digit, the first half of that 8th octet, 10 nn
, can only have four possible values:
10 00
(hex 8)
10 01
(hex 9)
10 10
(hex A)
10 11
(hex B)