Skip to content

Instantly share code, notes, and snippets.

@nieldeokar
Last active June 2, 2018 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nieldeokar/48cff62ac372cea25932fe2e1a3f659d to your computer and use it in GitHub Desktop.
Save nieldeokar/48cff62ac372cea25932fe2e1a3f659d to your computer and use it in GitHub Desktop.
Demonstration of how to set specific bit to 1
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