[转载] C++位运算:将一个4字节整数的二进制表示中的001替换为011

#include <iostream>
#include <assert.h> /**
* Key:
* * get someone bit: num & (mode1bit<<N)
* * check a few bits: num & (mode3bit<<shift) == What
*/
int replace(int num)
{
unsigned int mode3bit = ;
unsigned int mode1bit = ;
int shift = ;
int result = ;
while (shift < )
{
while (shift < && (num & (mode3bit<<shift)) != (<<shift))
{
result += (num & (mode1bit<<shift));
shift++;
}
if (shift >= )
{
break;
}
else if ( - shift < )
{
result += (num & (mode3bit<<shift));
break;
}
result += (<<shift);
shift += ; }
return result;
}
上一篇:MySQL简介


下一篇:dos命令对mysql操作