Error using bitxor in matlab -


i working on code in matlab, here module creating problem, follows:

    sum1=0 ;     sum2=0 ;          i=1:8         sum1=sum1+w1(i)*(2^(i-1));     end     i=1:8         sum2=sum2+w2(i)*(2^(i-1));     end     sum1=floor(sum1);     sum2=floor(sum2);     z8=floor(z8);     l1=bitxor(sum2,z8);     l2=bitxor(sum1,z8); 

here z8 , w1(i),w2(i) integer elements. whenever compile regular error

"error using bitxor double inputs must have integer values in range of assumedtype."

i saw documentation , tried adding assumedtype

i can't reconstruct error. placing in dummy values w1, w2 , z8, code works. therefore, can suggest check following things:

  1. you must make sure inputs bitxor non-negative , must have values less or equal 2^64 - 1. check sum1, sum2 , z8 , ensure case.

  2. make sure w1 , w2 only contain values of either 0 or 1. doing in sum1 , sum2 reconstructing base-10 representation of 8-bit unsigned number.

  3. because looks 8-bit unsigned integers, may prudent call bitxor additional parameter uint8 enforce conversion type:

    l1 = bitxor(sum2, z8, 'uint8'); l2 = bitxor(sum1, z8, 'uint8'); 

example run

w1 = [1 0 1 0 1 0 1 0]; w2 = 1 - w; z8 = 35; 

using above , running code, l1 , l2:

>> l1  l1 =     137  >> l2  l2 =     118 

Comments