we need to swap only if both the bits are not same if((n^(1<<i)<n)!=(n^(1<<j)<n)) n^=(1<<i)+(1<<j);
On 10/29/11, praveen raj <[email protected]> wrote: > int func(int x) > { > int y=(1<<i)+(1<<j); > int z=x&y; // if after bitwise and ..we get power of 2 then ... > we have to flip the bits.. > if((z&(z-1))==0) > return(x^y); > else > return x; > } > > With regards, > > Praveen Raj > DCE-IT > 9999735993 > [email protected] > >> >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
