I have to write a function which takes an integer array as input and it should return true if the array contains 1,2,3 or 4.

Conditions

1) The function should pass thru array only once.

2) Can use two local variable.

3) Preferably using bit manipulation.

Now suppose if the array has to be checked only for 1, 2 or 4 i have the solution.

Initialize the local var, say l_var = 0, i = 0(for array indexing)

Then pass thru the array using for loop and check

If

Array* == 1 || Array == 2 || Array == 4*

then

l_var = l_var | Array;

At the end of the loop check if l_var == 7

If its 7 return true;

Now I am not able to figure out how this can be done if 3 comes into picture. Since binary of 3 is 0011 (assuming 1 byte) I cannot use the above method.

Can anyone suggest some other solution.