Last active
June 2, 2018 06:53
-
-
Save nieldeokar/48cff62ac372cea25932fe2e1a3f659d to your computer and use it in GitHub Desktop.
Demonstration of how to set specific bit to 1
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
int myOriginalValue = 0b0010; | |
// STEP 1 : 0b0001 << 3 = 0b1000; | |
// STEP 2 : OR 0b0010; originalValue | |
// -------------- | |
// RESULT : 0b1010; // 3rd bit is set to true | |
// Formula for setting a bit : | |
// myOriginalValue = myOriginalValue | (1 << position); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment