Click here to Skip to main content
15,117,719 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to convert the long value: -279691878727680 to an unsigned long value. In C# I receive: 18446464381830823936 but in vb I am getting an arithmetic overflow exception. :confused:

Can someone pls. explain why there are differences between both environments and how can I solve that issue? The used framework is for both 2.0 (VS 2008).

Thank you,


Daniel.
Posted
Comments
Nish Nishant 31-Oct-10 12:50pm
   
Show your VB and C# code, and someone can point out what you are doing differently.
RaviRanjanKr 31-Oct-10 13:13pm
   
you need to show your code to justify what is actual error
Daniel Leykauf 31-Oct-10 13:36pm
   
VB: If (CULng(val) And &HFFFF000000000000UL) = &HFFFF000000000000UL ...
C#: if (((ulong)val & 0xFFFF000000000000) == 0xFFFF000000000000) ...
Nish Nishant 31-Oct-10 14:37pm
   
My guess is that those don't produce identical IL. I don't know VB.NET syntax, but is there a way you can actually do a direct cast, like in C#? Using CULng(...) may be an optimized VB specific call that results in IL that's different from what'd be generated if you do a direct cast (assuming VB syntax supports that).

Hi,

I could resolve it by disabling of integer overflow checks within the project properties. But I guess this is not the "finest" solution ...
Regards,


Daniel.
   
VB:
VB
If (CULng(val) And &HFFFF000000000000UL) = &HFFFF000000000000UL


C#:
C#
if (((ulong)val & 0xFFFF000000000000) == 0xFFFF000000000000)


My guess is that those don't produce identical IL. I don't know VB.NET syntax, but is there a way you can actually do a direct cast, like in C#? Using CULng(...) may be an optimized VB specific call that results in IL that's different from what'd be generated if you do a direct cast (assuming VB syntax supports that).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900