|
-
Sep 10th, 2012, 11:05 AM
#1
Thread Starter
New Member
Problems with varibles
hi guys 
I have this problem:
MsgBox(&H33 Xor &H34) will show the correct answer = "7"
but i ned to use varibles in stead so made this
EAX = 34
ECX = 33
MsgBox(ECX Xor EAX)
but this shows the wrong answer "3"
How can i fix it? (i know it show "3" because it thinks it is decimal but as the first code shows i need it to xor in hex)
could someone plz help me?
-
Sep 10th, 2012, 11:16 AM
#2
Re: Problems with varibles
I've never seen the Xor operator before, however after looking at the documentation it looks as though it is a boolean value. So I think that the first thing you should do is turn option strict and option explicit on and that would work out a few conversion errors for you.
-
Sep 10th, 2012, 11:36 AM
#3
Thread Starter
New Member
Re: Problems with varibles
i'm not sure i understand you solution because
this works as it should ---> MsgBox(&H33 Xor &H34) will show the correct answer = "7"
i just need a way to tell the program that the values in EAX and ECX should be treatet as hexvalue so
Msgbox(eax xor ecx) also gives "7"
-
Sep 10th, 2012, 11:37 AM
#4
Hyperactive Member
Re: Problems with varibles
Just declare some constants.
C#
Code:
const Int64 EAX = 0x034;
const Int64 ECX = 0x033;
MessageBox.Show((EAX ^ ECX).ToString());
VB.net
Code:
Const EXC As Int64 = &H34
Const ECX As Int64 = &H33
MessageBox.Show((EAX XOr ECX).ToString())
Both these examples will result in 7 as you're requiring.
-
Sep 10th, 2012, 11:53 AM
#5
Thread Starter
New Member
Re: Problems with varibles
wel i can't do that here are the whole code:
teller = 6
For k = 2 To teller
Delecx = Asc(Mid(Serial_after_check, EDX, 1))
ECX = Delecx.ToString("X2")
EBX = (EBX Xor ECX) <------here is the problem as you can see i can't declare it
EDX = EDX + 1
EAX = EAX - 1
Next k
in the first run of the loop EBX is 33 and ECX is 34 it should be 7 and stored in EBX but, i gives 3
-
Sep 10th, 2012, 01:59 PM
#6
Re: Problems with varibles
Do you understand the difference between a number and a string? Do you understand the difference between decimal and hexadecimal, and how they relate to numbers and strings?
You cannot perform an XOR function on a string. XOR is a bitwise operator, and requires a numeric value. In your example, the variable ECX is a string. Show your declarations, and work from there.
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
-
Sep 10th, 2012, 02:01 PM
#7
Re: Problems with varibles
Do you understand the difference between a number and a string?
That's why I suggested to the OP to turn option strict and explicit on. I haven't tested it, but I'm sure that if it was on, it would've thrown an error.
-
Sep 11th, 2012, 06:41 AM
#8
Re: Problems with varibles
 Originally Posted by dday9
That's why I suggested to the OP to turn option strict and explicit on. I haven't tested it, but I'm sure that if it was on, it would've thrown an error.
You are absolutely correct, of course. This should be the first order of the day
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
-
Sep 11th, 2012, 09:16 AM
#9
Re: Problems with varibles
Personally I think knowledge of the difference between a HEX (base 16) value and a DECIMAL (base 10) value needs to be understood... the OP is using 33 when he needs to use &H33 ... they are NOT the same values... Not even close.
&H33 xor &H34 does not produce the same value as 33 xor 34 ... so... if you're extracting HEX values from a string they need to be treated as their HEX values and not as their DECIMAL values... OR... you need to take the hex values and translate them to their decimal values, then xor the two decimal values.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|