Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting GUID to Integer and Back

Tags:

.net

asp.net

so I have a 3rd party application that I have to interface with, this application needs the userID from my users table. the problem is that I store my userIDs as GUIDs and the 3rd party app only accepts an integer. so I figure, if there is a way to convert a GUID to an integer then be able to convert it back (as i get communications from their server regarding the userID) then I don't have to recode a too much. any ideas?

like image 915
Russ Bradberry Avatar asked Nov 28 '22 05:11

Russ Bradberry


2 Answers

An integer uses 32 bits, whereas a GUID is 128 bits - therefore, there's no way to convert a GUID into an integer without losing information, so you can't convert it back.

EDIT: you could perhaps store the GUID into a GUIDs table where you assign each a unique integer ID. That way, you could get the GUID back given the integer ID.

like image 199
Mike Scott Avatar answered Dec 18 '22 14:12

Mike Scott


You'll need a store a mapping from your Guid to the 3rd party's integer: either a new "int thirdPartyId" field in your existing user table, or a new table.

like image 32
ChrisW Avatar answered Dec 18 '22 16:12

ChrisW