首页 > 其他 > 详细

位运算基础

时间:2015-11-27 23:30:04      阅读:228      评论:0      收藏:0      [点我收藏+]

 

             Binary
Value        Sample             Meaning
x 00101100 原始x的值 the original x value
~x 11010011 按位取反
-x 11010100 按位取反再加1
a|b 合并1
a&b 合并0
a^b 非进位加法,便于对某一位进行切换 x & -x 00000100 提取最末位1 extract lowest bit set x | -x 11111100 制造一块区域遮住最末位1及其左边区域 create mask for lowest-set-bit & bits to its left x ^ -x 11111000 制造一块区域遮住最末位1左边的区域 create mask bits to left of lowest bit set x & (x-1) 00101000 移除最末位1 strip off lowest bit set --> useful to process words in O(bits set) instead of O(nbits in a word) x | (x-1) 00101111 把最末尾1右边全部填为1 fill in all bits below lowest bit set x ^ (x-1) 00000111 制造一块区域遮住最末尾的1及其右部区域 create mask for lowest-set-bit & bits to its right ~x & (x-1) 00000011 制造一块区域遮住最末尾的1右边的区域 create mask for bits to right of lowest bit set x | (x+1) 00101101 最右边的0变1 toggle lowest zero bit x / (x&-x) 00001011 右移去掉所有最右边的0 shift number right so lowest set bit is at bit 0

 

 

占位符

位运算基础

原文:http://www.cnblogs.com/xuwangzihao/p/5001870.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!