|
-
Oct 15th, 2007, 05:59 PM
#1
Thread Starter
Frenzied Member
[2.0] have a number loop instead of overflow?
Well Sometimes I have a number that causes the integer to overflow when adding. Now is there a way that instead of overflowing it resets to 0 and continues adding? I was thinking making it a int64 and if it is bigger then an int subtracting an int but is there another easier way?
-
Oct 15th, 2007, 06:39 PM
#2
Re: [2.0] have a number loop instead of overflow?
If an Int32 value overflows then an exception is thrown. Catch the exception and reset your value.
OR
Use an Int64 and test its value against Int32.MaxValue, resetting if it becomes greater.
-
Oct 15th, 2007, 08:08 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] have a number loop instead of overflow?
Now why would this error? exact same thing in C++ works fine.
ret[1] = CurByte ^ CurEncByte;
Curbyte and CurEncByte are both a byte and ret is a byte array but it gives me the error.
Error 1 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) C:\Documents and Settings\High6\My Documents\Visual Studio 2005\Projects\CoProx\CoProx\CoClient.cs 38 22 CoProx
any idea?
-
Oct 15th, 2007, 08:20 PM
#4
Re: [2.0] have a number loop instead of overflow?
The result of this:is an int, not a byte, which is why the error message is telling you that you cannot implicitly convert it to a byte, which you're trying to do by assigning it to a byte variable.
Remember: C++ and C# are NOT the same language. The fact that something works in one has no bearing on whether it will work in the other. If they were the same language then they'd have the same name.
-
Oct 15th, 2007, 09:43 PM
#5
Thread Starter
Frenzied Member
Re: [2.0] have a number loop instead of overflow?
 Originally Posted by jmcilhinney
The result of this: is an int, not a byte, which is why the error message is telling you that you cannot implicitly convert it to a byte, which you're trying to do by assigning it to a byte variable.
Remember: C++ and C# are NOT the same language. The fact that something works in one has no bearing on whether it will work in the other. If they were the same language then they'd have the same name.
Ty, fixed it by converting them to int then back to byte.
-
Oct 15th, 2007, 09:54 PM
#6
Re: [2.0] have a number loop instead of overflow?
So what's the actual purpose here? To get the lowest order byte from that result and just ignore the rest?
-
Oct 16th, 2007, 10:47 AM
#7
Thread Starter
Frenzied Member
Re: [2.0] have a number loop instead of overflow?
 Originally Posted by jmcilhinney
So what's the actual purpose here? To get the lowest order byte from that result and just ignore the rest?
I was converting an encryption algorithm from asm to C#
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|