/*
@brief 測試一個數(shù)某一位是否為
@param 被測試數(shù)據(jù)
@param 測試位數(shù)
@return false:0 true: 1
*/
bool BitTest(int const *Base, int Offset)
{
if
(*Base>>Offset&0x01
== 1)
{
return
1;
}
else
return
0;
}
/*
@brief 設置某一個位為
@param 被設置數(shù)據(jù)
@param 測試位數(shù)
@return
*/
bool BitSet(int *Base, int Offset)
{
if
(Base==NULL
|| Offset<0 && Offset>sizeof(int)*8-1)
return
false;
int
mask = 0x01;
*Base
= (*Base) | (mask<<Offset);
return
true;
}
/*
@brief 重置某一位為
@param 被設置數(shù)據(jù)
@param 測試位數(shù)
@return
*/
bool BitReset(int *Base, int Offset)
{
if
(Base==NULL
|| Offset<0 && Offset>sizeof(int)*8-1)
return
false;
int
mask = 0x01;
*Base
= (*Base) & ~(mask<<Offset);
return
true;
}
/*
@brief 取反某一位數(shù)據(jù)
@param 被重置數(shù)據(jù)
@param Offset
*/
bool BitReverse(int *Base, int Offset)
{
if
(Base==NULL
|| Offset<0 && Offset>sizeof(int)*8-1)
return
false;
int
mask = 0x01;
if
((*Base>>Offset)&0x01
== 1)
*Base
= (*Base) & ~(mask<<Offset);
else
*Base
= (*Base) | (mask<<Offset);
}