Solved

Overflow Error with XOR operation

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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