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

XORing Hexadecimal (Java)

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
Asked:
nocturn4l
  • 5
  • 3
2 Solutions
 
for_yanCommented:
0
 
nocturn4lAuthor Commented:
that's using decimal though.. the input i'm reading is hex =T
0
 
for_yanCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
objectsCommented:
parse the hex string to an int then you can xor is per normal
0
 
for_yanCommented:
And then return result bacjk with Integer.toHexString()
0
 
nocturn4lAuthor Commented:
ok thx guys, testing and i'll be back
0
 
for_yanCommented:
  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
 
for_yanCommented:
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
 
nocturn4lAuthor 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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now