|
-
January 19th, 2007, 05:26 PM
#1
Exception on arithmetic operation
Why does this bit of code throw an exception?
dim dataBytes(5) as byte
dataBytes(0)=&H4A
dataBytes(1)=&H1
dataBytes(2)=&H1
dataBytes(3)=&H2A
dataBytes(4)=(dataBytes(1)+dataBytes(2)+dataBytes(3))^&HFF
The final statement is what generates the exception. The exception states that an arithmetic operation resulted in an overflow.
Thanks!
-
January 19th, 2007, 11:06 PM
#2
Re: Exception on arithmetic operation
To answer my own question...
I mixed C syntax with VB.net syntax. ^ is an XOR operation in C... in VB.net it's simply Xor. ^ is obviously valid in VB.net and so it didn't generate any errors. Dumb mistake... but I guess it's bound to happen when using both languages simultaneously.
-
January 20th, 2007, 01:47 AM
#3
Re: Exception on arithmetic operation
byte type represent 8-bit unsigned integers ranges b/w 0-255. the arithematic operation cause an overflow.
in vb.net ^ operator to raise a number to the power of an exponent.
so use the xor operator.
Code:
dataBytes(4) = (dataBytes(1) + dataBytes(2) + dataBytes(3)) Xor &HFF
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
|