MATLAB: Xor operation on two numbers

logical operation

i have two numbers 23 and 47, i have to convert them into binary and then perform the Xor operation how to do that

Best Answer

Since decimal to binary conversion may not produce same length of inputs to xor, we need to append 0's before the binary value
in1 = 27;
in2 = 47;
x = dec2bin(in1);
y = dec2bin(in2);
if length(x)~=length(y)
max_len = max(length(x), length(y));
x = [repmat('0', 1, max_len-length(x)), x];
y = [repmat('0', 1, max_len-length(y)), y];
end
result = xor(x-'0', y-'0');
Related Question