开发者

Practical bit operations that save hours of work

I am wondering what other bitwise and logical operations you've used that saved your day.

For example, my last great time (and resources') saver开发者_运维问答 has been

if(!((A^B) & B))

reads: if A has at least B's access rights, where rights were saved in the bit fields A and B.

Please use the classical operators: binary & (and) | (or), ^ (xor), ~ (invert) and the logical ones && (and), || (or), ! (not).


Mandatory link: http://graphics.stanford.edu/~seander/bithacks.html.


double negation rules: !! value result in 1 or 0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜