Forum Discussion
Andy_Herrman_22
Aug 10, 2007Nimbostratus
Another option would be to split the low value into two positive ints (basically, getting a lowLow and lowHigh value).
Here's what I mean (in pseudocode and extra verbose as I don't know VB and want to be clear):
int32 high = value.high;
int32 low = value.low;
int32 lowLow = value.low & 0x0000FFFF;
int32 lowHigh = (value.low >> 16) & 0x0000FFFF;
uint64 high64 = Convert.ToUInt64(high);
uint64 lowLow64 = Convert.ToUInt64(lowLow);
uint64 lowHigh64 = Convert.ToUInt64(lowHigh);
uint64 final = (high64 << 32) | (lowHigh64 << 16) | lowLow64;
return final;
By splitting the low value into two 16-bit values stored in 32-bit ints neither will be negative. This should fix the problem with Convert.ToUInt64.
If you're worried about the high value getting so large that it becomes negative then you might want to do the same to the high value, but that's up to you.
Hope that helps (and that it works)!