How can I xor a and b now?

2 views (last 30 days)
Adarsh Santhosh
Adarsh Santhosh on 20 Jan 2018
Commented: Adarsh Santhosh on 20 Jan 2018
I want to xor 2 hex values.
reshape(dec2bin(hex2dec(str(:)),4).',1,[])
I convert 2 hex values to binary using these and store it in a and b.
How to xor now?
Cant get using bitxor.
Is there an alternative.
I want two user inputted hex

Accepted Answer

James Tursa
James Tursa on 20 Jan 2018
Edited: James Tursa on 20 Jan 2018
Using the fact that XOR is basically a "not equals" operator for bits:
a = your first converted binary string
b = your second converted binary string
result = char((a~=b)+'0');
  1 Comment
Adarsh Santhosh
Adarsh Santhosh on 20 Jan 2018

I dropped dec2hex and did bitxor with decimal and then converted decimal answer to binary.

But,this works too and is much simpler.
Thanks.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!