开发者

Practical bit operations that save hours of work

开发者 https://www.devze.com 2023-01-19 03:58 出处:网络
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

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

精彩评论

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