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.


closed as off-topic by Tunaki, Marc-Andre, Dannnno, Quill, syb0rg Aug 4 '16 at 18:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


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))

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