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=xinput;

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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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
amir.hossein.shahri...@gmail.com 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 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
 for example if the result in the first step is zero the next step would be
 to compute n  0xFF00 to find whether the leftmost set bit is in the 8
 less significant bits or not

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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 sarma.debajy...@gmail.com
 wrote:

 for(i=sizeof(int)*8-1;i=0;i--)
 {
 if((numberi)1)
 {
 number=number^(1i);
 break;
 }
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: unset leftmost bit

2010-07-24 Thread sonic
#include stdio.h;

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));

  printf(\nThe number after unsetting the leftmost bit: %d, output);
  printf(\n);
}


On Jul 23, 8:15 pm, Tech Id tech.login@gmail.com wrote:
 Write a C function that unsets the leftmost set bit of an integer in
 less than order (n)
 n here is 32 (bit-length of an integer)
 Hint: do some bit-tricks

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



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
for example if the result in the first step is zero the next step would be
to compute n  0xFF00 to find whether the leftmost set bit is in the 8
less significant bits or not

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[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 tech.login@gmail.com wrote:
 Write a C function that unsets the leftmost set bit of an integer in
 less than order (n)
 n here is 32 (bit-length of an integer)
 Hint: do some bit-tricks

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: unset leftmost bit

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

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.