Wednesday, 27 March 2013

setBit CopyBits


void setBit(unsigned int& V, int bitNo, bool value){
  if(value){
    V = V | (1 << bitNo-1);
  }else{
    V = V & ~(1 << bitNo-1);
  }
}

void copyBits(unsigned int& V, int bitNo, int NoOfBits, unsigned int mask){
  unsigned int i;
  unsigned int m;
  bool value;
  for(i=bitNo; i<bitNo+NoOfBits; i++){
    m = 1 << i-1;
    value = mask & m;
    setBit(V, i, value);
  }
}

No comments:

Post a comment