Convert GUID to Numeric Equivalent

后端 未结 2 1557
无人共我
无人共我 2021-01-22 03:22

I\'ve been asked to export a list of users from ActiveDirectory, and Convert the GUIDs to a numeric equivalent for display (so I\'ll .ToString that after). I\'ve done some searc

相关标签:
2条回答
  • 2021-01-22 04:05

    "Numeric" doesn't make sense in VB w.r.t Guid. There is no 128-bit numeric types in .net. The only 128-bit type is Decimal; but that doesn't seem to make sense to convert a Guid to a Decimal. I would simply use ToByteArray and display the byte values as hex.

    Alternatively, make sure the last byte in the array given to BigInteger is zero to get a postive value. e.g.::

    var bytes = Guid.NewGuid().ToByteArray(); 
    Array.Resize(ref bytes, 17); 
    var bigInt = new BigInteger(bytes);
    var value = bigInt.ToString();
    
    0 讨论(0)
  • 2021-01-22 04:06

    You could simply convert Guid to numeric representation using ToString("n") :

    Guid.NewGuid().ToString("n")
    

    will return something like "5ee575bd995b419499aff6d6967c4a35"

    0 讨论(0)
提交回复
热议问题