[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Overflow Error with XOR operation

Posted on 2003-11-17
2
Medium Priority
?
364 Views
Last Modified: 2013-12-25
Hi everybody,
I wanted to calculate CRC and for this, I had written following code, but it gives me Overflow error. The error come in the line...
mCrc = mCrc Xor mStr         where...
mCrc = "1111111111111111"    (binary of 65535) and
mStr = "10"  (binary of 2)

Could you please help me out of this.
My code is:

Public mCrc
Public mTmpPoly
Public mTmpAsc
Public mTmpBin
Public mtmp

Private Sub Command1_Click()
Text2 = CalcCrc(Text1)
End Sub

Public Function CalcCrc(mStr As String)

mCrc = DecimalToBinary(65535)
mTmpPoly = DecimalToBinary(40961)
mStr = DecimalToBinary(2)
mCrc = mCrc Xor mStr

For i = 0 To 7
    mtmp = Right(mCrc, 1)
    mCrc = "0" & Left(mCrc, Len(mCrc) - 1)
Next

CalcCrc = mCrc
End Function

Sorry, if I have posted question to wrong zone.

thanks alot
0
Comment
Question by:hiren_d_in
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 300 total points
ID: 9764125
It looks as if you are unnecessarily converting your binary values to strings.
 2 xor 65535 will give 65533 as it stands
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9764988
By using setting
mCrc = "1111111111111111"    (binary of 65535) and
mStr = "10"  (binary of 2)

This sets the variant to a type of String, and internally it is represented as a string.  If you try using this string in a function that takes an int (such as XOR). Then behind the scenes an implicit CInt is called.

Thus the line
mCrc = mCrc Xor mStr

Is really
mCrc = CInt(mCrc) Xor CInt(mStr)
The Xor does not actually take 2 strings that represent a binary number, it takes 2 numbers and compares them bit by bit.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question