今天翻看两年前写的一个函数,咋一看还差点迷糊了
void setBitValue(int &v, int beg_b, int end_b, int bv)
{
int tv = pow(2, end_b - beg_b + 1) - 1;
bv &= tv;
tv = ~(tv << (beg_b - 1));
v &= tv;
v |= (bv << (beg_b - 1));
}
今天翻看两年前写的一个函数,咋一看还差点迷糊了
void setBitValue(int &v, int beg_b, int end_b, int bv)
{
int tv = pow(2, end_b - beg_b + 1) - 1;
bv &= tv;
tv = ~(tv << (beg_b - 1));
v &= tv;
v |= (bv << (beg_b - 1));
}