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

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -