Re: [algogeeks] Reverse the bits.

2011-06-11 Thread dinesh bansal
Thanks Guys I got it. @balaji... you are right.. it will work just fine. -Dinesh Bansal On Fri, Jun 10, 2011 at 10:22 PM, Vetri Balaji wrote: > int flip(int j,int k,int n) > { >   int t1=(1<   int t2=(1<   t1=t2^t1; > return n^t1; > } > correct me if im wrong > > On Fri, Jun 10, 2011 at 10:09 P

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Vetri Balaji
no..it will work just fine On Sat, Jun 11, 2011 at 3:31 AM, Anika Jain wrote: > @balaji: right , just one change required i think so coz in question they > are asking for change of one more bit i.e. for j=2,k=5.. bits 2,3,4,5 are > modified..ur code is doing i guess only 2,3,4.. i think just one

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Anika Jain
@balaji: right , just one change required i think so coz in question they are asking for change of one more bit i.e. for j=2,k=5.. bits 2,3,4,5 are modified..ur code is doing i guess only 2,3,4.. i think just one change needed int t2=(1<<(k+1))-1; On Fri, Jun 10, 2011 at 10:22 PM, Vetri Balaji wro

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Vetri Balaji
int flip(int j,int k,int n) { int t1=(1< wrote: > How about this??? > * > unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int > k) > { > unsigned int temp; > int num_of_on_bits = k-j+1; > > temp = (1< temp <<= j; > > return (n^temp); > }* > > I dont

Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Kunal Patil
How about this??? * unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k) { unsigned int temp; int num_of_on_bits = k-j+1; temp = (1< wrote: > How do you reverse the bits between j to k in a 32 bit integer. > > For e.g.: > > n = 11100011; j = 2 and k = 5 >

[algogeeks] Reverse the bits.

2011-06-10 Thread dinesh bansal
How do you reverse the bits between j to k in a 32 bit integer. For e.g.: n = 11100011; j = 2 and k = 5 output: 1101 (bits from 2 to 5 are reversed.) n = 11010110; j = 1 and k = 5 output: 11101000 O(1) method is preferred. Thanks, -- Dinesh Bansal The Law of Win says, "Let's not do it y