First time here? Check out the FAQ!

Ask Your Question
0

hexadecimal to binary

asked 0 years ago

Kaunil gravatar image

I have two hexadecimal strings from Hexadecimal string monoid. I want to XOR them. As there is no XOR function inbuilt, I wish to convert them to binary.

S=BinaryStrings()
H=HexadecimalStrings()
A=H('4ac0')
B=H('b53f')
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 0 years ago

Max Alekseyev gravatar image

There is no need to convert to binary to perform XOR, converting to a numerical value is enough. For example,

H=HexadecimalStrings()
A=H('4ac0')
B=H('b53f')
hex( eval('0x'+str(A)) ^^ eval('0x'+str(B)) )

gives 0xffff. If element of H is needed, one can use

H( hex( eval('0x'+str(A)) ^^ eval('0x'+str(B)) )[2:] )
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 0 years ago

Seen: 104 times

Last updated: Feb 28