471,348 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Is it possible to divide a UInt64 by another UInt64?

Hi,
I have a problem, I have to do this (MyUInt64 / MyOtherUInt64). the IDE
tells me that the / operator has not been overloaded for UInt64. Is there a
way I can do what I need to do?

Thanks
Jul 21 '05 #1
5 2800
In article <Ok**************@TK2MSFTNGP14.phx.gbl>,
NO*******@sympatico.caSPAMATALL says...
Hi,
I have a problem, I have to do this (MyUInt64 / MyOtherUInt64). the IDE
tells me that the / operator has not been overloaded for UInt64. Is there a
way I can do what I need to do?


I assume you're working in VB.NET? C# can handle dividing the UInt64
numbers. However, UInt64 is not CLS compliant. VB.NET makes it much
more difficult to write non-CLS compliant code.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Jul 21 '05 #2

"Patrick Steele [MVP]" <pa*****@mvps.org> a écrit dans le message de
news:MP************************@msnews.microsoft.c om...
In article <Ok**************@TK2MSFTNGP14.phx.gbl>,
NO*******@sympatico.caSPAMATALL says...
Hi,
I have a problem, I have to do this (MyUInt64 / MyOtherUInt64). the IDE tells me that the / operator has not been overloaded for UInt64. Is there a way I can do what I need to do?


I assume you're working in VB.NET? C# can handle dividing the UInt64
numbers. However, UInt64 is not CLS compliant. VB.NET makes it much
more difficult to write non-CLS compliant code.


Yes I work in VB.NET. I found that by writing (MyUInt64.ToString /
MyOtherUInt64.ToString), the division is done correctly... But I'm pretty
sure there is a better solution.

Is there a reason why C# can do it and VB.NET cannot? I mean, it's supposed
to be the same framework, it's supposed to compile to the exact same thing,
right? Why can one do what the other cannot?

thanks
Jul 21 '05 #3

"ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message
news:Ok**************@TK2MSFTNGP14.phx.gbl...
Hi,
I have a problem, I have to do this (MyUInt64 / MyOtherUInt64). the IDE tells me that the / operator has not been overloaded for UInt64. Is there a way I can do what I need to do?

Thanks


In VB.Net I assume? Unsigned Integers are not yet supported in VB.Net.
C# will allow you to work with unsigned Ints.

Options:
If you don't really need the values to be unsigned and signed Int64 will
work, use that instead. This is the preferred method.

If you still require the larger values that extra bit gives you, but you
don't have to use UInt64, then convert the values to Decimal format. Less
efficient than Int64, but a good alternative.

If you really need to keep them as UInt64's for whatever reason, and you
only have a few operations you need to do, then converting them temporarily
to Decimal and back is an option. For example:

Private Function UInt64Divide(ByVal Value1 As UInt64, ByVal Value2 As
UInt64) As UInt64
Dim a, b, c As Decimal

a = Convert.ToDecimal(Value1)
b = Convert.ToDecimal(Value2)
c = a \ b 'Note \ not / means Integer Division
Return Convert.ToUInt64(c)

End Function

If you really need them as UInt64's and have any reasonable amount of work
you need to do with them, then write a class in C# to handle all the things
you really need to do with them. Although take note that they are not
CLS-compliant. While you "can" work with them, it is not recommended,
especially if you expose any of them outside your class.

Gerald
Jul 21 '05 #4
In article <uK**************@TK2MSFTNGP15.phx.gbl>,
NO*******@sympatico.caSPAMATALL says...
Is there a reason why C# can do it and VB.NET cannot? I mean, it's supposed
to be the same framework, it's supposed to compile to the exact same thing,
right? Why can one do what the other cannot?


The goal of VB.NET was to be a simpler way to program in .NET. To that
end, the designers decided not to add support for non-CLS data types in
the language. However, I believe the next version of VB.NET will
support most (if not all) of the non-CLS data types (like unsigned
integers).

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Jul 21 '05 #5

"ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message
news:uK**************@TK2MSFTNGP15.phx.gbl...
Yes I work in VB.NET. I found that by writing (MyUInt64.ToString /
MyOtherUInt64.ToString), the division is done correctly... But I'm pretty
sure there is a better solution.
I believe that the values are being cast to the first value that will
satisfy the / operator.
So if the String value is "123456" then those strings are probably being
cast to Integers.
If they are really greater than a standard Int64 value, by 1 Bit, then they
will be cast to Decimals.

Is there a reason why C# can do it and VB.NET cannot? I mean, it's supposed to be the same framework, it's supposed to compile to the exact same thing, right? Why can one do what the other cannot?


Communication and planning issues if I recall. Unsigned Integers are not CLS
compliant. Originally neither language was going to support it. Then they
were. Then they weren't. etc.
At one point, VB.Net had them in there I believe. Along with some BitWise
operators I liked, but that's another story.
The decision was made to pull them from the languages to keep them CLS
compliant.
They got pulled from VB, but never did from C#.
In the end, sometimes you just need that one extra bit. After much
discussion I'm sure, I believe they have decided to re-introduce them in VB
2005.

Gerald
Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Kevin | last post: by
9 posts views Thread by Sanjib Biswas | last post: by
5 posts views Thread by stuie_norris | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.