Skip to content

Instantly share code, notes, and snippets.

@nieldeokar
Last active May 30, 2018 13:36
Show Gist options
  • Save nieldeokar/b8840abf741bccc44949afb9822749ca to your computer and use it in GitHub Desktop.
Save nieldeokar/b8840abf741bccc44949afb9822749ca to your computer and use it in GitHub Desktop.
Used for storing multiple boolean values into one int variable. This snippet checks the bit values set in SetAppUpdateAvailable.java
public class GetAppUpdateAvailable {
private int mUpdateValue = 0b0010;
private static final int UPDATE_AVAILABLE = 1;
private static final int UPDATE_COMPULSORY = 2;
public void getUpdateAvailable(){
boolean result = false;
result = (mUpdateValue & (1 << UPDATE_AVAILABLE)) != 0;
// This is how above line will get executed
// result = (0b0010 & (0b0001 << 1)) != 0; // STEP 1 : Does Bitwise left shift by 1
// result = (0b0010 & (0b0010)) != 0; // STEP 2 : Does Bitwise AND
// result = (0b0010 != 0); // RESULT : Compare output with 0
// result = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment