[algogeeks] BIT MANIPULATION

2011-07-09 Thread Piyush Sinha
I found a good question to try for bit manipulation.Try it... :) Given an integer x, find out the smallest integer which has same number of set bits as x and is greater than x. For example if the input integer is 12 (1100) then your function should return 17(10001). If the input integer is

Re: [algogeeks] BIT MANIPULATION

2011-07-09 Thread Aman Goyal
Solutn: 1101000 Start from rightmost bit-leftmost bit Find the starting and ending 1’s positions, here 3 and 7 If any 0 bw them… while traversing.. (bitwise r-l).. make it 1 and other adjacent right ” 1” as “0”. And this is your new no. here 111 If you find no “0” in bw ( eg for

Re: [algogeeks] BIT MANIPULATION

2011-07-09 Thread Yogesh Yadav
int count1=count2=0; given number=n; int m=n; //save in temp variable m while(m!=0) //count number of bits in given number { m=m (m-1); count1++; } m=n; //save in temp variable m while(count1!=count2) //check no. of bits same or not { m=m+1;

[algogeeks] Bit Manipulation

2011-01-16 Thread Decipher
Q1)An array A[1 n] contains all the integers from 0 to n except for one number which is missing . In this problem, we cannot access an entire integer in A with a single operation . The elements of A are represented in binary, and the only operation we can use to access them is “fetch the jth