Overflow Error with XOR operation

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)

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
Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RetiredCommented:
It looks as if you are unnecessarily converting your binary values to strings.
2 xor 65535 will give 65533 as it stands
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.