[algogeeks] Bitwise operator - Adobe

2010-09-25 Thread Krunal Modi
Q: Write an algorithm to compute the next multiple of 8 for a given positive integer using bitwise operators. Example, (a) For the number 12, the next multiple of 8 is 16. (b) For the number 16, the next multiple of 8 is 24. - I have written a code using bitwise

Re: [algogeeks] Bitwise operator - Adobe

2010-09-25 Thread Terence
If +,-,*,/ is completely forbidden, I think at least one loop is needed. Here is my solution: int next8mult (int n) { n = (n ~7);// clear the least 3 bit to make multiple of 8 int r = 8; while(r) { // add 8 to n int r1 = (nr) 1; // get