• Status: Solved
• Priority: Medium
• Security: Public
• Views: 453

Say I have an input of a hexadecimal of f6.. and another hex of 15.. and i want to xor the two.. so

f6 ^ 15 = e3

is there any way to do this easily in Java?  i don't really see anything in the API unless I overlooked it... thanks
0
nocturn4l
• 5
• 3
2 Solutions

Commented:
0

Author Commented:
that's using decimal though.. the input i'm reading is hex =T
0

Commented:
But this operator ^ works for any integer
if you parse
first using Integer.parseInt(String, 16)
so you'll get your int numbers and can XoR them
0

Commented:
parse the hex string to an int then you can xor is per normal
0

Commented:
And then return result bacjk with Integer.toHexString()
0

Author Commented:
ok thx guys, testing and i'll be back
0

Commented:
``````  int a = 0xf6;
int b= 0x15;

int c = a ^ b;

System.out.println(Integer.toHexString(c));
System.out.println("c: " + c);
``````

Output:

``````e3
c: 227
``````
0

Commented:
Or even so:

``````   String sA= "F6";
String sB = "15";

int a = Integer.parseInt(sA,16);
int b=Integer.parseInt(sB,16);

int c = a ^ b;

System.out.println(Integer.toHexString(c));

System.out.println("c: " + c);
``````

``````e3
c: 227
``````
0

Author Commented:
thanks, fast replies with quick solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.