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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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);