c / c ++ bit arithmetic function



// a reversed, the i-th bit.
// Obviously, a type of char, etc. can also be replaced.

void
flipBit ( int & a, int i) {   a ^ = ( . 1 << i); }

// Get a first i.
int GETBIT ( int a, int i) {   return (i >> a) & . 1 ; }

// set in a bit i.
void setBit(int & a,int i,int value) { if(value) a|=(1<<i); else a&=~(1<<i); }
 

 

Guess you like

Origin www.cnblogs.com/cq0143/p/11241869.html