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 m = 1 << (bitNo - 1);
unsigned int check;
int i;
for(i = 0; i < NoOfBits; i++){//using setBit();
check = mask & m;
setBit(V, bitNo++, check);
m <<= 1;
}
/*for (i = 0; i < NoOfBits; i++){
check = mask & m;
if (check) {
V = V | m;
}
else {
V = V & ~m;
}
m <<= 1;
}*/
}
No comments:
Post a Comment