I'm attempting to use java's Bitwise & operator and I think I'm misusing it. Using the below example, with messageAddress of 7 both condition 1 and condition 3 are satisfied. Shouldn't a messageAddress of 7 just meet the 3rd condition and not the first? Any ideas on how to change the below logic so that messageAddress of 7 would only meet the last condition?
public static final int SLOW = 1;
public static final int SMEDIUM = 2;
public static final int SHIGH = 3;
String messageAddressHex="7";
int messageAddress = Integer.parseInt(messageAddressHex, 16);
if ((messageAddress & SLOW) == SLOW) {
//condition 1 met logic
} else if ((messageAddress & SMEDIUM) == SMEDIUM) {
//condition 2 met logic
} else if ((messageAddress & SHIGH) == SHIGH) {
//condition 3 met logic
}