Can someone explain me what this code is doing?? void main() { int n,m i,j; int max = ~0; // 1's through position j, then 0's int left = max - (( 1 << j) - 1); //1' after position i int right = (( 1<< i) -1) // 1's with 0's betwwen i and j int mask = left | right ; // clear i through j , then put m in there return ( n & mask ) | ( m << i) }
On Tue, Sep 20, 2011 at 10:11 PM, Dave <dave_and_da...@juno.com> wrote: > @Ishan: Using bitwise operations: > > N = (N & ~((2 << j) - (1 << i) | (M << i); > > Dave > > On Sep 20, 2:03 am, Ishan Aggarwal <ishan.aggarwal.1...@gmail.com> > wrote: > > You are given two 32-bit numbers, N and M, and two bit positions, i and > > j.Write a method to set all bits between i and j in N equal to M (e.g., M > > becomes a substring of N located at i and starting at j). > > > > EXAMPLE: > > > > Input: N = 10000000000, M = 10101, i = 2, j = 6 > > > > Output: N = 10001010100 > > > > -- > > Kind Regards > > Ishan Aggarwal > > [image: Aricent Group] > > Presidency Tower-A, M.G.Road,Sector-14 > > Gurgaon,Haryana.122015 INDIA > > Phone : +91-9654602663 > > ishan2.aggar...@aricent.com <puneet.ar...@aricent.com> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > > -- Kind Regards Ishan Aggarwal [image: Aricent Group] Presidency Tower-A, M.G.Road,Sector-14 Gurgaon,Haryana.122015 INDIA Phone : +91-9654602663 ishan2.aggar...@aricent.com <puneet.ar...@aricent.com> -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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.