-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[System.Guid] Discrepancy when constructing same Guid from string or byte array #29523
Comments
the first 12 letters (00000000-0000) bit is in fact a 8-byte integer and 4-byte integer, not just 8 and 4 1-byte data I believe. Probably endianess thing. |
e.g. 0x6b, 0xa7, 0xb8, 0x10 is 0x6BA7B810 when interpreted as integer on big-endian machines but 0x10B8A76b when interpreted as integer on little-endian machines. (i.e. x86-64 and ARM machines) |
https://en.m.wikipedia.org/wiki/Universally_unique_identifier See "format" section |
Though, is there a standard on the endianess when interpreting GUID/UUIDs? that wikipedia article seem to state this:
But also:
assuming it's the latter case I think the behaviour is expected, however could it be useful to provide a way to interpret the GUIDs encoded in the former format? |
Spot on, that's exactly what it's doing. Thanks! I really believe this behavior should be more clearly mentioned[1] in the docs, because the string-based constructor interprets all the supported input formats as a whole big-endian bitstream, and the [1] It is mentioned in the remarks of the |
@1ma perhaps you'd like to offer a PR for the docs? https://github.com/dotnet/dotnet-api-docs |
I'll see if I can manage. |
Since the ctor is behaving as designed, and the proposed documentation update would be in a different repository, I'm going to go ahead and close this issue. |
I recently noticed that when you construct a Guid from a byte array you might not get the exact same Guid you described, as it happens when it is constructed from a string. In particular the 8 bytes in the higher groups seem to be flipped (
9dad
turns toad9d
, etc).On the other hand, the
00000000-0000-0000-0000-000000000000
Guid passes the above test.If this behaviour is correct I think that the documentation for the
Guid(byte[])
method could be expanded a bit, explaining the relationship between Guid byte and string representation, and the algorithm to convert one form to the other.Additional information:
The text was updated successfully, but these errors were encountered: