Sunday, 11 November 2012

Week11_setBit(unsigned int val, unsigned int bitNo, bool bitVal)

Sets the "bitNo" bit of val to the "bitVal" value:
 
unsigned int setBit(unsigned int val, unsigned int bitNo, bool bitVal){
    if(bitVal) {
        val = val | (1 << bitNo);
    }
    else {
        val = val & ~(1 << bitNo);
    }
    return val;
}

No comments:

Post a Comment