MATLAB Answers

Bit xor of row with the next row and the output is again xored with the next row

1 view (last 30 days)
Hi, I have a image and I want to xor first row with single number then Xor 2nd row with first, the output is xored aith the next row and so on. I hope some one can figure out the mistake
for example
c=245;
A=[23 2 13;34 56 70;12 18 90];
a=[];
[m n]=size(A);
for i=2:m
a1=bitxor(c,A(1,:)); %Xor c with each element of first row of A
(a(i),:)=bitxor(a(i-1),A(i,:));% error ,Index exceeds matrix dimension
end

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Jul 2020
c = 245;
A = [23 2 13;34 56 70;12 18 90];
a = [];
[m, n] = size(A);
a(1,:) = bitxor(c,A(1,:)); %Xor c with each element of first row of A
for i = 2:m
a(i,:) = bitxor(a(i-1),A(i,:));
end

  3 Comments

lilly lord
lilly lord on 2 Jul 2020
I am checking it with simple values like
c=11;
A=[3 2 13;4 5 7;12 8 9];
a=[];
[m n]=size(A);
a(1,:)=bitxor(c,A(1,:));
for i=2:m
a(i,:)=bitxor(a(i-1),A(i,:));
end
a;
The output is
8 9 6
12 13 15
0 4 5
which is a wrong
Correct output should be
8 9 6
12 12 1
0 4 8
Can u please figure out where is the problem

Sign in to comment.

More Answers (0)


Translated by