Last active
May 30, 2018 13:31
-
-
Save nieldeokar/ac80df805e3dc57570e24528936d745d 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nileshdeokar.healthapp; | |
public class GetAppUpdateAvailable { | |
private int updateValue = 0b0110; | |
private static final int UPDATE_AVAILABLE = 1; | |
private static final int UPDATE_COMPULSORY = 2; | |
public void getUpdateAvailable(){ | |
boolean result = false; | |
result = (this.updateValue & (1 << UPDATE_AVAILABLE)) != 0; | |
// This is how above line will get executed | |
// result = (0b0010 & (0b0001 << 1)) != 0; // Do the Bitwise left shift by 1 | |
// result = (0b0010 & (0b0010)) != 0; // Do the Bitwise AND | |
// result = (0b0010 != 0); // Compare output with 0 | |
// result = true; | |
} | |
public void getUpdateCompulsary(){ | |
boolean result = false; | |
result = (this.updateValue & (1 << UPDATE_COMPULSORY)) != 0; | |
// This is how above line will get executed | |
// result = (0b0110 & (0b0001 << 2)) != 0; // Do the Bitwise left shift by 2 | |
// result = (0b0110 & (0b0100)) != 0; // Do the Bitwise AND | |
// result = (0b0100 != 0); // Compare output with 0 | |
// result = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment