Again it is giving the same error. on changing it to 32.
On Tue, Sep 20, 2011 at 2:18 PM, abhinav gupta <[email protected]>wrote: > Instead of Num[31] u should tk Num[32] > > On Tue, Sep 20, 2011 at 2:16 PM, Ishan Aggarwal < > [email protected]> wrote: > >> Hi, >> >> When I am running this program, I am getting segmentation fault. Can u plz >> confirm where is the error. >> >> #include<stdio.h> >> void main() >> { >> int Num[31]={0}; >> int Mum[31]={0}; >> int n = 64,m = 7 ,i=0,j=3,k; >> for(k=31;k>=0;k++) >> { >> Num[k]=n & 1; >> Mum[k]=m & 1; >> n=n>>1; >> m=m>>1; >> } >> >> for(k=i;k<=j;k++) >> Num[k]=Mum[k]; >> >> for(k=0;k<=31;k++) >> printf("%d ", Num[k]); >> } >> >> >> On Tue, Sep 20, 2011 at 1:49 PM, tec <[email protected]> wrote: >> >>> mask = (1<<(j+1))-(1<<i); >>> n = (n&(~mask)) | m; >>> >>> >>> On Sep 20, 3:43 pm, abhinav gupta <[email protected]> wrote: >>> > You can also solve the problem by using bit operators. by using >> << & >>> | ! >>> > . >>> > Need sm thinking in dat..No time rite nw! >>> > >>> > On Tue, Sep 20, 2011 at 1:12 PM, abhinav gupta < >>> [email protected]>wrote: >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > > Its because o/p should look like dat.Bt dats simple you can do it >>> > > by multiplying bits to power(2, i) and >>> > > adding all expressions.Simple! >>> > > On Tue, Sep 20, 2011 at 1:09 PM, abhinav gupta < >>> [email protected]>wrote >>> > >>> > > In the first loop bits are added into the array N and M .I have >>> taken two >>> > >> integers n and m . >>> > >> Caution : >>> > >> declare >>> > >>> > >> int N[31]={0}; >>> > >> int M[31]={0}; >>> > >> int n,m,i,j; >>> > >>> > >> On Tue, Sep 20, 2011 at 1:02 PM, Ishan Aggarwal < >>> > >> [email protected]> wrote: >>> > >>> > >>> What are u doing in the first loop running for k=31 to k =0? >>> > >>> > >>> On Tue, Sep 20, 2011 at 12:50 PM, abhinav gupta < >>> > >>> [email protected]> wrote: >>> > >>> > >>>> U can use single walker (from 0 till 31) to convert integers N and >>> M >>> > >>>> into array of bits, then >>> > >>>> another walker from i to j to replace values. >>> > >>> > >>>> for(k=31;k>=0;k++) >>> > >>>> { >>> > >>>> N[k]=n & 01; >>> > >>>> M[k]=m &01; >>> > >>>> n>>=1; >>> > >>>> m>>=1; >>> > >>>> } >>> > >>> > >>>> for(k=i;k<=j;k++) >>> > >>>> N[k]=M[k]; >>> > >>> > >>>> On Tue, Sep 20, 2011 at 12:44 PM, abhinav gupta < >>> > >>>> [email protected]> wrote: >>> > >>> > >>>>> I can tell you the logic.Take two arrays N and M, put their bits >>> in >>> > >>>>> the array. >>> > >>>>> Now using i and j index replace the value of N[j] to n[i] by M[j] >>> to >>> > >>>>> M[i]. >>> > >>>>> On Tue, Sep 20, 2011 at 12:33 PM, Ishan Aggarwal < >>> > >>>>> [email protected]> 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 >>> > >>>>>> [email protected] <[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. >>> > >>> > >>>>> -- >>> > >>>>> @ |3 # ! /\/ @ \./ >>> > >>> > >>>> -- >>> > >>>> @ |3 # ! /\/ @ \./ >>> > >>> > >>>> -- >>> > >>>> 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. >>> > >>> > >>> -- >>> > >>> Kind Regards >>> > >>> Ishan Aggarwal >>> > >>> [image: Aricent Group] >>> > >>> Presidency Tower-A, M.G.Road,Sector-14 >>> > >>> Gurgaon,Haryana.122015 INDIA >>> > >>> Phone : +91-9654602663 >>> > >>> [email protected] <[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. >>> > >>> > >> -- >>> > >> @ |3 # ! /\/ @ \./ >>> > >>> > > -- >>> > > @ |3 # ! /\/ @ \./ >>> > >>> > -- >>> > @ |3 # ! /\/ @ \./ >>> >>> -- >>> 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. >>> >>> >> >> >> -- >> Kind Regards >> Ishan Aggarwal >> [image: Aricent Group] >> Presidency Tower-A, M.G.Road,Sector-14 >> Gurgaon,Haryana.122015 INDIA >> Phone : +91-9654602663 >> [email protected] <[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. > -- Kind Regards Ishan Aggarwal [image: Aricent Group] Presidency Tower-A, M.G.Road,Sector-14 Gurgaon,Haryana.122015 INDIA Phone : +91-9654602663 [email protected] <[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.
