Reputation: 3070
I want to implement xor bitwise together. For example, I have two bits pair that are 6 (110) and 3 (011). Now I want to implement bitwise xor of two inputs. It can do by bitxor function in matlab.
out=bitxor(6,3);%output is 5
But I want to implement the scheme by mod function instead of bitxor. How to do it by matlab?Thank you so much. it is my code
out=mod(6+3,2^3) %2^3 because Galois field is 8 (3 bits)
Upvotes: 1
Views: 198
Reputation: 221574
Code
function out = bitxor_alt(n1,n2)
max_digits = ceil(log(max(n1,n2)+1)/log(2));%// max digits binary representation
n1c = dec2bin(n1,max_digits); %// first number as binary in char type
n2c = dec2bin(n2,max_digits); %// second number as binary in char type
n1d = n1c-'0'; %// first number as binary in double type
n2d = n2c-'0'; %// second number as binary in double type
out = bin2dec(num2str(mod(n1d+n2d,2),'%1d')); %// mod used here
return;
Upvotes: 3