[algogeeks] Re: adobe question help

2012-09-13 Thread Navin Gupta
  int temp = {[1(j-+1)]i-1};
  Here temp is a number with all the bits set between positions i  j [both 
inclusive]  
  temp = ~temp;
  N = N  temp;   // here we are clearing all the bits of N from 
position i to j 
  temp = temp | M;   // now we are taking the bit pattern from M into temp  
in the given positions
  N = N | temp;// now again we are setting the same pattern from 
temp into N.

Note :- clearing bit means bit set to zero , while setting bit means bit is 
1

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/QTXreMoSy6gJ.
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.



Re: [algogeeks] Re: adobe question help

2012-09-13 Thread Ashish Goel
this is from KR exercise :)
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Wed, Sep 12, 2012 at 4:14 PM, Navin Gupta navin.nit...@gmail.com wrote:

   int temp = {[1(j-+1)]i-1};
   Here temp is a number with all the bits set between positions i  j
 [both inclusive]
   temp = ~temp;
   N = N  temp;   // here we are clearing all the bits of N from
 position i to j
   temp = temp | M;   // now we are taking the bit pattern from M into
 temp  in the given positions
   N = N | temp;// now again we are setting the same pattern from
 temp into N.

 Note :- clearing bit means bit set to zero , while setting bit means bit
 is 1


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/QTXreMoSy6gJ.

 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.


-- 
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.



[algogeeks] Re: adobe question help

2011-10-02 Thread ravi ojha
in the first loop the value of k shuld vary from 0 to j-i.

On Oct 1, 7:26 am, rahul sharma rahul23111...@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 = 100, M = 10101, i = 2, j = 6
 Output: N = 10001010100
 _

 #includestdio.h
 #includestdlib.h
 int main()
 {
     int N,M,i,j;
     printf(Enter value  of N \n);
     scanf(%d,N);
     fflush(stdin);
     printf(Enter value  of M \n);
     scanf(%d,M);
     fflush(stdin);
     printf(Enter value  of i \n);
     scanf(%d,i);
     fflush(stdin);
     printf(Enter value  of j \n);
     scanf(%d,j);
     fflush(stdin);
     int a=0,k;
     for( k=0;kj;k++)
     {
               a= a1;
               a=a|1;
     }
     for(k =0;ki;k++)
     {
           a=a1;
     }

     N = N (~a);
     printf(value of N is %d,N);
     for(k=0;ki;k++)
     M=M1;
     N=N|M;
     printf(value of N is %d,N);
     getchar();

 }

 isnt it give us wrong mask

 say i=2;

 j=6;

 it gives mask as(i.e ~a)

 0011

 but i think from 2 to 6 5 0's are neededplz tell the above prog is
 ok???or not???check by giving any input whose 7thy bit is set...thnx
 in advance

-- 
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.



Re: [algogeeks] Re: adobe question help

2011-10-02 Thread rahul sharma
yeah u r ryt.

On Sun, Oct 2, 2011 at 4:20 PM, ravi ojha rbojha...@gmail.com wrote:

 in the first loop the value of k shuld vary from 0 to j-i.

 On Oct 1, 7:26 am, rahul sharma rahul23111...@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 = 100, M = 10101, i = 2, j = 6
  Output: N = 10001010100
  _
 
  #includestdio.h
  #includestdlib.h
  int main()
  {
  int N,M,i,j;
  printf(Enter value  of N \n);
  scanf(%d,N);
  fflush(stdin);
  printf(Enter value  of M \n);
  scanf(%d,M);
  fflush(stdin);
  printf(Enter value  of i \n);
  scanf(%d,i);
  fflush(stdin);
  printf(Enter value  of j \n);
  scanf(%d,j);
  fflush(stdin);
  int a=0,k;
  for( k=0;kj;k++)
  {
a= a1;
a=a|1;
  }
  for(k =0;ki;k++)
  {
a=a1;
  }
 
  N = N (~a);
  printf(value of N is %d,N);
  for(k=0;ki;k++)
  M=M1;
  N=N|M;
  printf(value of N is %d,N);
  getchar();
 
  }
 
  isnt it give us wrong mask
 
  say i=2;
 
  j=6;
 
  it gives mask as(i.e ~a)
 
  0011
 
  but i think from 2 to 6 5 0's are neededplz tell the above prog is
  ok???or not???check by giving any input whose 7thy bit is set...thnx
  in advance

 --
 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.



-- 
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.



Re: [algogeeks] Re: adobe question help

2011-10-02 Thread rahul sharma
can u tell in this we have to set i and j also or only between elements
say if i=2 and j=6
then
whether we should set bit no 2,3,4,5,6,
or 3,4,5

acc. to me its 2,3,4,5,6,
and ur logic also give that answer
plz tell??

On Sun, Oct 2, 2011 at 4:38 PM, rahul sharma rahul23111...@gmail.comwrote:

 yeah u r ryt.


 On Sun, Oct 2, 2011 at 4:20 PM, ravi ojha rbojha...@gmail.com wrote:

 in the first loop the value of k shuld vary from 0 to j-i.

 On Oct 1, 7:26 am, rahul sharma rahul23111...@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 = 100, M = 10101, i = 2, j = 6
  Output: N = 10001010100
  _
 
  #includestdio.h
  #includestdlib.h
  int main()
  {
  int N,M,i,j;
  printf(Enter value  of N \n);
  scanf(%d,N);
  fflush(stdin);
  printf(Enter value  of M \n);
  scanf(%d,M);
  fflush(stdin);
  printf(Enter value  of i \n);
  scanf(%d,i);
  fflush(stdin);
  printf(Enter value  of j \n);
  scanf(%d,j);
  fflush(stdin);
  int a=0,k;
  for( k=0;kj;k++)
  {
a= a1;
a=a|1;
  }
  for(k =0;ki;k++)
  {
a=a1;
  }
 
  N = N (~a);
  printf(value of N is %d,N);
  for(k=0;ki;k++)
  M=M1;
  N=N|M;
  printf(value of N is %d,N);
  getchar();
 
  }
 
  isnt it give us wrong mask
 
  say i=2;
 
  j=6;
 
  it gives mask as(i.e ~a)
 
  0011
 
  but i think from 2 to 6 5 0's are neededplz tell the above prog is
  ok???or not???check by giving any input whose 7thy bit is set...thnx
  in advance

 --
 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.




-- 
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.