0
\$\begingroup\$

Is there any better way than doing:

if ((newState & InputState.DEFAULT) == InputState.DEFAULT)

? My InputState.class defines static int variables to the power of 2 that are being ORed with an int to make it possible to determine more than one input state. However, checking the existence of a set bit like this looks just odd to me (and means writing alot of code that is obvious to come anyway) I was wondering whether there is a better solution to that.

\$\endgroup\$
1
\$\begingroup\$

You can always write an utility method.

public static bool CheckMask(int value, int mask){
    return (value & mask) == mask;
}

Use it:

if(CheckMask(newState, InputState.DEFAULT))
| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.