1

I have the following GUID 0d9fc5f5-f2f2-477c-a876-a6ece127ea60

Is there an only tool converter. Or Can I use some C# lib to do the conversion

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
ABID KHAN
  • 35
  • 6
  • GUIDs are bigger than 32-bits, what are you trying to accomplish? – josh poley Mar 24 '20 at 21:54
  • 1
    You cannot convert that to an int32, because it contains a lot more than 32 bits of data. – Jonathan Hall Mar 24 '20 at 21:54
  • Requests for libraries are also off-topic. – Jonathan Hall Mar 24 '20 at 21:55
  • I am trying to convert to a number like for example -2147483612. I am not sure how the developers at my work place are converting it to a such number. I need to convert it to this type because the API call requires an int32. When I convert it to a BigInteger I get this error "JSON integer 326686967456717362525701059217570916960 is too large or small for an Int32" – ABID KHAN Mar 24 '20 at 22:00

1 Answers1

2

No idea what you're trying to achieve but here you go:

int x = new Guid("0d9fc5f5-f2f2-477c-a876-a6ece127ea60").GetHashCode();

Collisions are possible and you can't avoid it, since a GUID contains 128 bits and a int only 32. (see pigeon hole principle).

Is x related to the Guid in any way? no. Again, not sure what you're trying to achieve, the code above is really not very different from generating a random 32 bits number.

jods
  • 4,581
  • 16
  • 20
  • This is not a conversion. A conversion is impossible. Maybe a hash will work, but you should be sure that it answers the question before providing this answer. – Jonathan Hall Mar 25 '20 at 07:00
  • @Filmzy Can you give me your definition of the word "conversion" please? I understand it as: mapping a value from one type to another. Under that description GetHashcode is very much a conversion. I argee I have no idea if it's gonna help as the goal is not clearly stated, that's why I wrote twice: "No idea what you're trying to achieve". But it definitely takes a guid and transforms it deterministically into a int. – jods Mar 26 '20 at 19:48
  • Converting a data type means to change from one type to another. You are not converting from one type to another. You are performing a hash operation. That is entirely unrelated. – Jonathan Hall Mar 26 '20 at 22:03