Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
s1 = '0x54'
s2 = '0xa1'
How do we XOR s1 and s2 to get '0xf5' as output?
0x54 ^ 0xa1
First convert them to numeric values:
n1 = int(s1, 0) n2 = int(s2, 0)
Now compute the XOR of the values using the ^ operator, and convert to hex format:
XOR
^
hex
result = hex(n1 ^ n2)
Add a comment
s1 = '0x54' s2 = '0xa1' def XOR(s1, s2): return "0x" + "{:x}".format(int(s1[2:], 16)^int(s2[2:], 16)) XOR(s1,s2)
That should work
RUN:
print(hex(int(s1,16)^int(s2,16)))
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
0x54 ^ 0xa1??