Forum Discussion
Mike_Thompson_9
Nimbostratus
Aug 08, 2007CommonULong64 OverflowException
I am trying to convert the CommonULong64 type to UInt64 in .NET for a CommonStatistic type. Sometimes this works fine and I get a good number back. Other times I get a System.OverflowException. The...
Andy_Herrman_22
Nimbostratus
Aug 10, 2007Another 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)!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects