Solved

Posted on 2011-05-08
Medium Priority
448 Views
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
Question by:nocturn4l
• 5
• 3

LVL 47

Expert Comment

ID: 35717573
0

Author Comment

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

LVL 47

Accepted Solution

for_yan earned 1000 total points
ID: 35717584
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

LVL 92

Assisted Solution

objects earned 1000 total points
ID: 35717585
parse the hex string to an int then you can xor is per normal
0

LVL 47

Expert Comment

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

Author Comment

ID: 35717588
ok thx guys, testing and i'll be back
0

LVL 47

Expert Comment

ID: 35717589
``````  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

LVL 47

Expert Comment

ID: 35717596
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 Closing Comment

ID: 35717599
thanks, fast replies with quick solution
0

## Featured Post

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
###### Suggested Courses
Course of the Month8 days, 16 hours left to enroll