Archive for March 9, 2012

METHOD 1

bool isOn(unsigned int val, int bitNo){
  return (val>>bitNo)%2;
}

bool isOff(unsigned int val, int bitNo){
  return (~val>>bitNo)%2;
}

METHOD 2

bool isOn(unsigned int val, int bitNo){
  return ((val>>bitNo)!=(val>>(bitNo+1))<<1);
}

bool isOff(unsigned int val, int bitNo){
  return ((val>>bitNo)==(val>>(bitNo+1))<<1);
}