void printBits(unsigned int V){
for(int i=sizeof(unsigned int)*8-1;i>=0;!((i+1)%4) && putchar(' '),putchar('0' + !!(V & (1<<i))), (!i) && putchar('\n'),i--);
}
void SetBitPattern(unsigned int& val, const char* bitPattern, int startBitIndex){
int i = -1;
while(bitPattern[++i]);
while(i--){
if(bitPattern[i]-'0'){
val = val | 1 << startBitIndex;
}
else{
val = val & ~(1 << startBitIndex);
}
startBitIndex++;
}
}
没有评论:
发表评论