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 CommonULong64 value going in has a high of 4 and a low of -176378626 which does not look right, but that is what is coming back from the SOAP call. Here is my converstion function:
Public Shared Function Build64(ByVal value As Object) As UInt64
Return Convert.ToUInt64(value.high << 32 Or value.low)
End Function
Any ideas?
20 Replies
- Mike_Thompson_9
Nimbostratus
I think I finally have it!Public Shared Function Build64(ByVal value As Object) As UInt64 Dim ui64High As UInt64 = (value.high << 32) Dim ui64Low As UInt64 = CLng("&H" & (Hex("&H" & Hex(value.low)))) Return Convert.ToUInt64(ui64High Or ui64Low) End Function
Public Shared Function Build64(ByVal value As Object) As UInt64 Return Convert.ToUInt64((value.high << 32) Or CLng("&H" & (Hex("&H" & Hex(value.low))))) End Function
- Mike_Thompson_9
Nimbostratus
Yeah, Yeah, bang on the VB developer :'( Yes, I know. I do need to drop the VB and move to C at some point, but this app was written in VB so that is what I am going with and what I know (for now). Here are the definitions of the two functions: - Mike_Thompson_9
Nimbostratus
I converted your code to VB (yes, VB) and it does work. Considering speed, do you think your method is faster:Public Shared Function Build64(ByVal value As Object) As UInt64 Dim High As Int32 = value.high Dim Low As Int32 = value.low Dim lowLow As Int32 = value.low And &HFFFF Dim lowHigh As Int32 = (value.low >> 16) And &HFFFF Dim high64 As UInt64 = Convert.ToUInt64(High) Dim lowLow64 As UInt64 = Convert.ToUInt64(lowLow) Dim lowHigh64 As UInt64 = Convert.ToUInt64(lowHigh) Dim final As UInt64 = (high64 << 32) Or (lowHigh64 << 16) Or lowLow64 Return myfinal End Function
- Mike_Thompson_9
Nimbostratus
All "bashing" aside, your help has been invaluable and I cannot thank you enough! Below is the final function that resolved the issue:Public Shared Function Build64(ByVal value As Object) As UInt64 Return (Convert.ToUInt64(value.high) << 32) Or (Convert.ToUInt64((value.low >> 16) And &HFFFF) << 16) Or Convert.ToUInt64(value.low And &HFFFF) End Function
- You all absolutely ROCK! This is what community is all about and what makes our little slice of the net so rewarding to us here at DC.
- Don_MacVittie_1Historic F5 Account
Posted By bikemike on 08/10/2007 9:26 AM
Public Shared Function Build64(ByVal value As Object) As UInt64 Return (Convert.ToUInt64(value.high) << 32) Or (Convert.ToUInt64((value.low >> 16) And &HFFFF) << 16) Or Convert.ToUInt64(value.low And &HFFFF) End Function
- Mike_Thompson_9
Nimbostratus
So, you are saying I should be doing something like this:Public Shared Function Build64(ByVal value As Object) As String Return FormatNumber((Convert.ToUInt64((value.high >> 16) And &HFFFF) << 16) Or _ Convert.ToUInt64(value.high And &HFFFF) Or _ (Convert.ToUInt64((value.low >> 16) And &HFFFF) << 16) Or _ Convert.ToUInt64(value.low And &HFFFF), 0) End Function
- Mike_Thompson_9
Nimbostratus
I really need to take a moment to review this function and figure out the inner workings. To some extent I understand what is going on, but not fully. That is why I had to keep coming back to you guys for verification of my changes. - Andy_Herrman_22
Nimbostratus
Doing it in Java should be trivial. The High and Low values are both longs, which are already 64 bits in Java, so no casting is needed. I believe just doing this will work:long value = (high << 32) | low;
- Don_MacVittie_1Historic F5 AccountIt's been done in Java for a while, this conversation just made me want to check it over again.
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