Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  48] [ 1]  / answers: 1 / hits: 16333  / 11 Years ago, fri, december 13, 2013, 12:00:00
var hex1 = B1C85C061C98E713DEF0E2EDDDDB432738674C9F8962F09B75E943D55F9FB39F;
var hex2 = 121B0D3327A21B8048FC7CA6FD07AACC0D8DF59B99DB098686696573E3686E6C;

var result = hex1 ^ hex2; //XOR the values

console.log(result); // outputs: 0 which does not sound good.


Any ideas how to perform XOR operations on hex values?


More From » javascript

 Answers
138

Bitwise operations in JavaScript only work on numeric values.



You should parseInt(hexString, 16) your hex string before. Specifically in your case this wouldn't work because your hex is too big for a number. You would have to create your own customized XOR function.



Take a look at this link: How to convert hex string into a bytes array, and a bytes array in the hex string?



The resulting bytearray will be ellegible for a manual XOR. Byte by byte. Maybe this will help: Java XOR over two arrays.


[#73743] Thursday, December 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maurodannyr

Total Points: 126
Total Questions: 103
Total Answers: 105

Location: Maldives
Member since Sun, Feb 27, 2022
2 Years ago
;