Arduino sketch from truth table

There's more to it than that, some bits are indeterminate. The read must be masked before the compare.

Also the first 2 bits can limit or eliminate compares.