经典位运算收集
收集在各个开源项目中遇到的经典的位运算代码:
OPENCV:
/* min & max without jumps */ #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))) #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))) /* absolute value without jumps */ #define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) /*compare*/ #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) /*juage sign*/ #define CV_SIGN(a) CV_CMP((a),0)