VB.net XOR operation using HEX
I want to calculate a BCC XOR in hex using Visual Basic 2012 for the following String: H enter * in hex (48 0D 2A) using the following rule: Step 1. BCCXOR = 00h BCCXOR = 00 Step 2. BCCXOR = BCCXOR xor 48 BCCXOR xor first character - result BCCXOR = 48h Step 3. BCCXOR = BCCXOR xor 0D BCCXOR xor second character - result BCCXOR = 44h Step 4. BCCXOR = BCCXOR xor 2A BCCXOR xor third character - result BCCXOR = 6Fh
My code is:
Dim BCCXOR As Integer = &H0 For i As Integer = 0 To TextBox1.TextLength - 1 BCCXOR = (BCCXOR) Xor Conversion.Hex(Strings.Asc(TextBox1.Text.Substring(i, i + 1).ToString())) Next BCCXOR = BCCXOR Xor Hex(&HD) BCCXOR = BCCXOR Xor Hex(&H2A) TextBox2.Text = BCCXOR
My problem is that I receive an error message when I'm trying to calculate BCCXOR xor 0D I receive an error like: Conversion from string "D" to type 'Long' is not valid.
The Hex fonction converts a number to a string. I don't think this is what you want. Just remove the fonction call and it should work.
BCCXOR = BCCXOR Xor &HD BCCXOR = BCCXOR Xor &H2A