Solved

Overflow Error with XOR operation

Posted on 2003-11-17
2
338 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 100 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now