Solved

Overflow Error with XOR operation

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 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