toggling setting clearing checking changing a bit in c

Solutions on MaxInterview for toggling setting clearing checking changing a bit in c by the best coders in the world

showing results for - "toggling setting clearing checking changing a bit in c"
Michela
20 Jul 2017
1// Setting a bit
2number |= 1UL << n;
3// Clearing a bit
4number &= ~(1UL << n);
5// Toggling a bit
6number ^= 1UL << n;
7// Checking a bit
8bit = (number >> n) & 1U;
9// Changing the nth bit to x
10number ^= (-x ^ number) & (1UL << n);