I need to write d so that when the bit of c is 1, the corresponding bit in the result is the corresponding bit in b,
when c == 1 d = b
but when the bit of c is 0, the corresponding bit in the result is the corresponding bit in a.
when c == 0 d = a
This sounds like a job for bit masking!
I know you give these as your test data:
int a = 0b1011011011; int b = 0b1000110110; int c = 0b0101010101; int d = 0b1010011110;
But this test data is just as good a test and easier to read. All I've done is rearrange the bit columns so that c doesn't change so often:
int a = 0b11011_01101; int b = 0b10101_00110; int c = 0b00000_11111; int d = 0b11011_00110;
Since Java 7 we can also use underscores in numeric literals to make them a little easier on the eyes.
It should now be easy to see that c controls where d is copied from, a or b. Easy to read data is important too.
And now, some bit masks
assertTrue(b & c ==0b00000_00110); assertTrue(a & ^c==0b11011_00000);
Or them together and you get:
int d = 0b11011_00110; assertTrue(d == (b & c) | (a & ^c));
Try that with either data set. Should still work.
You could xor them together as well. Doesn't matter because the c mask negation already excludes the potential for 1's on both sides. I chose or simply out of a sense of tradition.
(a & ~c) ^ (b & c)? Not quite right but it's a starting point.