Is there a way to distinguish a GUID from just a random number?

浪子不回头ぞ 提交于 2019-12-30 09:20:06

问题


Being able to distinguish a GUID from random data can be useful when debugging obscure code defects.

On Windows each GUID generated is of version 4 therefore it has '4' as the first half-byte of the third part. So if the 16-byte sequence violtates that rule it is not a version 4 GUID. For example,

567E1ECB-EA1C-42D3-A3ED-87A5D824D167

could be either a version 4 GUID or anything else, but

567E1ECB-EA1C-02D3-A3ED-87A5D824D167 //third section starts with 0, not with 4

is not a version 4 GUID.

What are other signs of a 16-byte memory block being or not being a valid GUID?


回答1:


GUID's are hexadecimal, so you could check what characters are included (i.e. 'X', 'Y', etc. are not valid)

Check wikipedia for the definition and you could probably find out more ideas there.

http://en.wikipedia.org/wiki/Globally_Unique_Identifier




回答2:


Besides GUID version (0100), there's also something called the GUID variant. This will be 2 bits (10) in octet 8. The remaining bits a of v4 GUID are by definition random.



来源:https://stackoverflow.com/questions/1771410/is-there-a-way-to-distinguish-a-guid-from-just-a-random-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!