PDA

Click to See Complete Forum and Search --> : [2.0] have a number loop instead of overflow?


high6
Oct 15th, 2007, 05:59 PM
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?

jmcilhinney
Oct 15th, 2007, 06:39 PM
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.

high6
Oct 15th, 2007, 08:08 PM
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?

jmcilhinney
Oct 15th, 2007, 08:20 PM
The result of this:CurByte ^ CurEncByteis 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.

high6
Oct 15th, 2007, 09:43 PM
The result of this:CurByte ^ CurEncByteis 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.

jmcilhinney
Oct 15th, 2007, 09:54 PM
So what's the actual purpose here? To get the lowest order byte from that result and just ignore the rest?

high6
Oct 16th, 2007, 10:47 AM
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#