You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
940 B
C

#pragma once
//位运算函数
//PortVal 的PortIdx 位设置为1
inline long SetBitOn(long Val,int Idx)
{
Val= Val |(1<<Idx);
return Val;
}
inline void SetIntBitOn(int &Val,int Idx)
{
Val= Val |(1<<Idx);
}
inline void SetIntBitOff(int &Val,int Idx)
{
Val = (Val)&(~(1<<Idx));
}
inline void SetIntBitState(int &Val,int Idx,bool bOn)
{
if(bOn)
SetIntBitOn(Val,Idx);
else
SetIntBitOff(Val,Idx);
}
//PortVal 的PortIdx 位设置为0
inline BYTE SetBitOff(BYTE Val,int Idx)
{
Val = (Val)&(~(1<<Idx));
return Val;
}
//判断某位是否为1,PortIdx 从右到左
inline BOOL IsBitOn(BYTE Val,int Idx)
{
if((Val>>Idx)&1)
return TRUE;
else
return FALSE;
}
inline BOOL IsBitOn(int Val,int Idx)
{
if((Val>>Idx)&1)
return TRUE;
else
return FALSE;
}
inline long SetBitByBool(BYTE Val,int Idx,bool b)
{
if(b)
return SetBitOn(Val,Idx);
return SetBitOff(Val,Idx);
}