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.
精彩评论