Re: [algogeeks] Re: unset leftmost bit

2010-07-25 Thread Manjunath Manohar
@amir hossein... Can u pls elaborate on the binary search...i donot have that much of a knowledge about hexadecimal representation of numbers..kindly pls help me.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send e

[algogeeks] Re: unset leftmost bit

2010-07-25 Thread Tech Id
binary search with bitwise is excellent. It will guarantee searching in log32 = 5 lookups. Great! On Jul 24, 5:00 pm, Amir hossein Shahriari wrote: > we can use a binary search to search for the bit in O(logn) > the search would look like this: > we first compute > n & 0x (which is 16 1s

Re: [algogeeks] Re: unset leftmost bit

2010-07-25 Thread Manjunath Manohar
will this work... int x= 127; //in binary it is interpreted with MSB set to 0.. and all other bits to 1 temp=x&input; temp will have the MSB unset.. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to al

[algogeeks] Re: unset leftmost bit

2010-07-24 Thread Dave
int ClearHighestBitSet (unsigned int n) { double x; int exp; x = frexp((double)n, &exp); return n ^ (1 << (exp-1)) } To see how it works, look up the standard C++ function frexp. Dave On Jul 23, 10:15 am, Tech Id wrote: > Write a C function that unsets the leftmost set bit of

Re: [algogeeks] Re: unset leftmost bit

2010-07-24 Thread Amir hossein Shahriari
we can use a binary search to search for the bit in O(logn) the search would look like this: we first compute n & 0x (which is 16 1s and 16 0s) if the result is 0 then the left most 1 is in the 16 less significant bits else it is in the 16 more significant bits then we can continue this way

[algogeeks] Re: unset leftmost bit

2010-07-24 Thread sonic
#include ; main() { int input,output; int temp; int counter=0; printf("\nEnter the number: "); scanf("%d", &input); temp=input; while(temp) { counter++; temp>>=1; } printf("\n[debug] the length of the binary no. is : %d", counter); output = input^(1<<(counter-1))

Re: [algogeeks] Re: unset leftmost bit

2010-07-24 Thread Ashish Goel
this algo sets all bits to zero Debajyoti refer http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sat, Jul 24, 2010 at 10:20 AM, Debajyoti Sarma wrote: > for(i=sizeof(int)*8-

[algogeeks] Re: unset leftmost bit

2010-07-23 Thread Debajyoti Sarma
for(i=sizeof(int)*8-1;i>=0;i--) { if((number>>i)&1) { number=number^(1