logic - how do I find if any bit of x equals 1 in C -


using bit-wise , logical operations, how can detect if bit of x equals 1 in c? no loops, if/else, ==, or !=

someone proposed (x & ~0) && 1, i've been looking @ hours , still don't know how (x & ~0) && 1 can detect if bit of x equals 1

!!x it.

this convert values 1, except 0 stays 0. , compilers can optimize intelligently.


Comments

Popular posts from this blog

node.js - StackOverflow API not returning JSON -

python - Subclassed QStyledItemDelegate ignores Stylesheet -

php - Laravel 4.1 to Heroku: SQLSTATE[HY000] [2002] No such file or directory -