I have two strings
String s1="426F62";
String s2="457665";
The strings are in hex representation. I want to XOR them. XORing normally character by character gives the correct result for others except F XOR 6.(It gives 112, the answer should be 9)
Please tell me the correct way to implement it in JAVA
EDIT: Converting to int and xoring works. But how to xor when two strings are of different length.
Rather than XORing the Unicode representations, just convert each character into the number it represents in hex, XOR those, then convert it back to hex. You can still do that one character at a time:
Note that this should work however long the strings are (so long as they’re the same length) and never needs to worry about negative values – you’ll always just get the result of XORing each pair of characters.