Answers for "toggling setting clearing checking changing a bit in c"

C
0

toggling setting clearing checking changing a bit in c

// Setting a bit
number |= 1UL << n;
// Clearing a bit
number &= ~(1UL << n);
// Toggling a bit
number ^= 1UL << n;
// Checking a bit
bit = (number >> n) & 1U;
// Changing the nth bit to x
number ^= (-x ^ number) & (1UL << n);
Posted by: Guest on November-21-2020

Code answers related to "C"

Browse Popular Code Answers by Language