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.com>wrote:

> 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 = 10000000000, M = 10101, i = 2, j = 6
>> > Output: N = 10001010100
>> > _
>> >
>> > #include<stdio.h>
>> > #include<stdlib.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;k<j;k++)
>> >     {
>> >               a= a<<1;
>> >               a=a|1;
>> >     }
>> >     for(k =0;k<i;k++)
>> >     {
>> >           a=a<<1;
>> >     }
>> >
>> >     N = N &(~a);
>> >     printf("value of N is %d",N);
>> >     for(k=0;k<i;k++)
>> >     M=M<<1;
>> >     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)
>> >
>> > 1111111100000011
>> >
>> > but i think from 2 to 6 5 0's are needed????plz 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.

Reply via email to