how to xor r1 , r2 and resolve the following error?

2 views (last 30 days)
x5 = '510E527FADE682D1'; bx5 = base2dec(x5,16); e = dec2bin(bx5,64); r1 = circshift(e,[0 +14]); disp(r1); r2 = circshift(e,[0 +18]); disp(r2); r12 = bitxor(r1,r2); sum1e = bitxor(r12,r1);
where the the error obtained here is ??? Undefined function or method 'bitxor' for input arguments of type 'char'.
Error in ==> round at 54 r12 = bitxor('r1','r2'); how to resolve it

Answers (2)

Guillaume
Guillaume on 1 Nov 2014
All the bit* functions operate on numbers not binary strings representation of numbers. You actually don't need to convert to a binary representation to do your shift (use bitshift on the decimal number) or xor:
x5 = '510E527FADE682D1';
bx5 = base2dec(x5,16);
r1 = bitshift(bx5, -14);
dec2bin(r1, 64) %for you to check that it did the right thing
r2 = bitshift(bx5, -18);
dec2bin(r2, 64) %for you to check that it did the right thing
r12 = bitxor(r1, r2);
sum1e = bitxor(r12, r1);

Andrei Bobrov
Andrei Bobrov on 1 Nov 2014
x5 = '510E527FADE682D1';
bx5 = base2dec(x5,16);
e = dec2bin(bx5,64);
r1 = circshift(e,[0 +14])-'0';
disp(r1);
r2 = circshift(e,[0 +18])-'0';
disp(r2);
r12 = bitxor(r1,r2);
sum1e = bitxor(r12,r1);

Community Treasure Hunt

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

Start Hunting!