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
Post a Comment