?
Solved

XORing Hexadecimal (Java)

Posted on 2011-05-08
9
Medium Priority
?
448 Views
Last Modified: 2012-05-11
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
Comment
Question by:nocturn4l
  • 5
  • 3
9 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35717573
0
 

Author Comment

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

Accepted Solution

by:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 92

Assisted Solution

by:objects
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

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

Author Comment

by:nocturn4l
ID: 35717588
ok thx guys, testing and i'll be back
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35717589
  int a = 0xf6;
        int b= 0x15;


        int c = a ^ b;

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

Open in new window


Output:

e3
c: 227

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
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);

Open in new window



e3
c: 227

Open in new window

0
 

Author Closing Comment

by:nocturn4l
ID: 35717599
thanks, fast replies with quick solution
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question