Thursday 28 March 2013

SetBit  function that  sets the bit of a given integer by doing a bitwise OR and using left shift

void SetBit(unsigned int& v, int bitNo, bool val){
   
       if(val == true){
          v = (1<<(bitNo - 1) | v;
       }
       else{
               v = ~(1<<(bitNo-1)) & v;
       }
 }

 

No comments:

Post a Comment