c - Bitwise operators: Printing the numbers 1 to 100 using bit manipulation -


i believe possible generate numbers 1 100 using bitwise operations or bit manipulation, rather traditional increment instruction.

what possible methods of doing this?

i believe there couple of ways achieve it. 1 of them use tilde operator ~x bitwise complement , equal -(x+1)

int increase(int x){    return (-(~x)); } 

so increment value above-mentioned function , print it.

apart own answer, found way make addition bitwise operators.

int add(int x, int y) {     if (y == 0)         return x;     else         return add( x ^ y, (x & y) << 1); } 

just substitute y 1 , way of incrementing value.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -