inline int CheckBit(char c, int siOffSet) { char tmpc = 0x01 << (siOffSet-1); return (c & tmpc); } inline char SetBit(char c, int siOffSet) { char tmpc = 0x01 << (siOffSet-1); c |= tmpc; return c; } inline int CheckIntBit(int i, int siOffSet) { int tmpc = 0x00000001 << (siOffSet-1); return (i & tmpc); } inline int SetIntBit(int i, int siOffSet) { int tmpc = 0x00000001 << (siOffSet-1); i |= tmpc; return i; } inline int Count(int i) //from <编程之美> { int siNum = 0; while(i) { i &= (i - 1); siNum++; } return siNum; }
对于long或者int要用CheckIntBit