c++ - `(x+7)&~7`,把x增大为稍大于x的8的倍数。这怎么理解?
阿神
阿神 2017-04-17 15:23:27
0
1
555

stl源码剖析的第61页有上面的位运算,不过我不了解,求证明。

阿神
阿神

闭关修行中......

모든 응답(1)
PHPzhong

7 = 00000111b
& is bitwise AND
so the x&7 has the only 3 low bits of x.


~7 = 11111000b

so the x&~7 will set x's 3 low bits to 0, and it is the multiple of 8.


(x+n-1)&(n-1),把x增大稍大于x的n的倍数,前提是n必须为 2^m
because only 2^m-1 has the type : high bits must be 1, low bits must be 0, not intersected.

subnet mask 子网掩码

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!