Page 1 of 1

Hopeless with bitwise operators

PostPosted: 09 Oct 2012, 19:47
by mcrawford620
OK, I'm a dunce with bitwise operators.

In the CardColor class, given another CardColor, I want to find all colors that are NOT in the base CardColor.
So if my base CardColor is Green, and I pass in a Green-White, I want to get White out.

Something like:
Code: Select all
public CardColor getOffColors(CardColor ccOther) {
    return CardColor.fromMask(~this.myColor & ccOther.myColor);
}
which is not right. What is the correct operator combo?

Re: Hopeless with bitwise operators

PostPosted: 09 Oct 2012, 20:51
by mcrawford620
Ah, duh, I had it right all along. I had just misunderstood the return value, because in my mind I flipped the base object and the operand. Never mind.