473,372 Members | 909 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 2966
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: donbro | last post by:
If my read of the extension source (Mac/Modules/file/_Filemodule.c) is correct, the parameter sizes specified for data and resource file sizes are UInt32 where they should be UInt64. In both OS9...
2
by: Luke Morehead | last post by:
I'm trying to use DsEnumerateDomainTrusts to generate a list of trusted domains in VB.NET. The code I've listed below generates the error, "An unhandled exception of type...
12
by: Wolfgang Kaml | last post by:
Dear all, I am using the following code to retrieve the size of a certain file and the available (free) space on the disk. The problem is, that I get the size of the file returned as a Long and...
8
by: Kevin | last post by:
Dim X as int32 Dim Y as int64 X = Y / 1024 gives me the error: "Operator is not valid for type 'UInt64' and type 'Integer'." I'm new to VB.NET and this is one of the reasons why I've...
5
by: ThunderMusic | last post by:
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
9
by: Sanjib Biswas | last post by:
Could anyone point out to me the difference between ulong (C#) and UInt64/ULong (VB.Net)? I was under the impression that both are same. Below C# code works fine for a particular value of 'data'...
5
by: stuie_norris | last post by:
Hi Group I am trying to write a method to unpack a byte array into an Uint64. But the results are wrong. public static void UnpackUint64(ref UInt64 dst, byte Data, ref uint Index) { dst =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.