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...
Aug 08, 2007
Ahh, the fun that is VB...
First, yes, those values you have (4, and -176378626) are valid. We use signed types because of java's limitations with support for unsigned types.
You have the correct algorighm (high << 32 | low) but the issue is with VB's builtin types being 32 bits. So, when you have a high large number for your high value, the first shift-left of 32 bits results in an overflow since the default size is 32 bits. I don't believe you can cast a 32 bit value to a 64 bit value like you can with C so when I tinkered around with this, I had to create new 64 bit types and assign them manually. This should work for you:
Public Function Build64(ByVal value As Object) As UInt64
Dim ui64High As UInt64 = value.high
Dim ui64Low As UInt64 = value.low
ui64High = ui64High << 32
Return Convert.ToUInt64(ui64High Or ui64Low)
End Function
There may be a way to condense this but since I'm by no means a VB guru, this is the best I could come up with. I did verify that the outcome of this function is the same as it's C counterpart:
public UInt64 build64(CommonULong64 ul64)
{
return (((UInt64)(UInt32)ul64.high) << 32) | ((UInt64)(UInt32)ul64.low);
}
Hope this helps...
-Joe
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