中级农民
- 积分
- 278
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2011-2-2
- 最后登录
- 1970-1-1
|
https://github.com/writecoffee/c ... blob/master/5.4.cpp
////////////////////////////////////////////////////////////////////////////////////
// GIST
// judge whether n has only one bit flipped on or not
//
// WHY IS THAT
// 1. n-1 flips the least significant 1 bit (x) and all zero bit lower than that,
// so excluding the higher bits (for those between bit (x+1) and 31), n&(n-1)
// generates 0.
// 2. after that, we can put sight on bit between (x+1) and 31, for which can
// influence the final result
//
// OBSERVATION
// by observation, this expression can only apply to positive interger
// and the smallest negative number (-2^31), which most significant bit
// is set to 1; except that, all negtive number has at least 2 bits on
////////////////////////////////////////////////////////////////////////////////////
|
|