# Answer to Question #2996 in MatLAB | Mathematica | MathCAD | Maple for geminia

Question #2996

Hi <br>

I just need a little help with matlab <br>

say if you have an array [2 5 10]<br>

and you have a result from a different function say y=8<br>

and want to find which numbers of the array have the same highest binary digit with y in the case <br>above y=[1000] and 2=[0010] 5=[0101] 10=[1010] so the only number in the array which has the same highest binary digit with 8 is 10.

<br>How can i do this in matlab?

I just need a little help with matlab <br>

say if you have an array [2 5 10]<br>

and you have a result from a different function say y=8<br>

and want to find which numbers of the array have the same highest binary digit with y in the case <br>above y=[1000] and 2=[0010] 5=[0101] 10=[1010] so the only number in the array which has the same highest binary digit with 8 is 10.

<br>How can i do this in matlab?

Expert's answer

function mx=q2996(y,x)

n=floor(log2(y)+1);

l=length(x);

mx=[];

for k=1:l

if floor(log2(x(k))+1)==n

mx=[mx x(k)];

end;

end;

mx=q2996(8,[2 5 10 12 16 18])

mx = 10 12

n=floor(log2(y)+1);

l=length(x);

mx=[];

for k=1:l

if floor(log2(x(k))+1)==n

mx=[mx x(k)];

end;

end;

**Example:**mx=q2996(8,[2 5 10 12 16 18])

mx = 10 12

## Comments

## Leave a comment