ok. got it Nitin. thanx :)
Sanju :) On Sun, Aug 21, 2011 at 10:06 AM, Nitin Nizhawan <nitin.nizha...@gmail.com>wrote: > I guess, earlier sarvan simply wanted to calculate > result = SUM {0<=i < N } A[i]*(8^i) > > in which > 8^i = 2^(3*i) which is equivalent to right shifting 3*i > > since each A[i] is octal it is just 3bits long , we need not add we can > simply shift and do OR. > > > On Sun, Aug 21, 2011 at 10:16 PM, Sanjay Rajpal <srn...@gmail.com> wrote: > >> @Nitin : could u explain ur logic ? >> >> >> Sanju >> :) >> >> >> >> On Sun, Aug 21, 2011 at 9:24 AM, Nitin Nizhawan <nitin.nizha...@gmail.com >> > wrote: >> >>> @sanjay, oops, my intention was bitwise OR >>> >>> >>> On Sun, Aug 21, 2011 at 4:25 PM, sarvesh saran < >>> aquarian.thun...@gmail.com> wrote: >>> >>>> Hi Prakash, >>>> >>>> I'll paste the exact description of the problem: >>>> >>>> A non-empty array A of N elements contains octal representation of a >>>> non-negative integer K, i.e. each element of A belongs to the interval [0; >>>> 7] (both ends included). >>>> >>>> Write a function that returns the number of bits set to 1 in the binary >>>> representation of K. >>>> >>>> thanks, >>>> >>>> Sarvesh >>>> >>>> >>>> >>>> >>>> >>>> >>>> i.e take any decimal number, convert to base 8 and then store each digit >>>> of base 8 representation in an array. >>>> >>>> So the question is, given such an array get back the original number. >>>> >>>> thanks, >>>> Sarvesh >>>> >>>> >>>> On Sun, Aug 21, 2011 at 4:13 PM, Prakash D <cegprak...@gmail.com>wrote: >>>> >>>>> A[i]<<3*i >>>>> >>>>> why is it needed to convert from base 8 to base 10?? >>>>> >>>>> On Sun, Aug 21, 2011 at 4:07 PM, Sanjay Rajpal <srn...@gmail.com>wrote: >>>>> >>>>>> Hi your intention was logical OR or BITWISE OR ? >>>>>> >>>>>> u did Logical. >>>>>> Sanju >>>>>> :) >>>>>> >>>>>> >>>>>> >>>>>> On Sun, Aug 21, 2011 at 3:30 AM, sarvesh saran < >>>>>> aquarian.thun...@gmail.com> wrote: >>>>>> >>>>>>> Hi Nitin, >>>>>>> >>>>>>> thanks that makes sense. I will try that out. >>>>>>> >>>>>>> I have another question. Is there a really fast way of converting a >>>>>>> hexadecimal string say "02F9A" to its decimal representation in C++? >>>>>>> >>>>>>> thanks, >>>>>>> Sarvesh >>>>>>> >>>>>>> thanks, >>>>>>> Sarvesh >>>>>>> >>>>>>> >>>>>>> On Sun, Aug 21, 2011 at 3:41 PM, Nitin Nizhawan < >>>>>>> nitin.nizha...@gmail.com> wrote: >>>>>>> >>>>>>>> int num = 0; >>>>>>>> for(int i=0;i<A.size();i++){ >>>>>>>> num=num||(A[i]<<3*i); >>>>>>>> } >>>>>>>> printf("%d",num); >>>>>>>> >>>>>>>> I think this will do. Given the number is with in the range of >>>>>>>> integer. >>>>>>>> >>>>>>>> >>>>>>>> On Sun, Aug 21, 2011 at 3:40 PM, Nitin Nizhawan < >>>>>>>> nitin.nizha...@gmail.com> wrote: >>>>>>>> >>>>>>>>> int num = 0; >>>>>>>>> for(int i=0;i<A.size();i++){ >>>>>>>>> num=num||(A[i]<3*i); >>>>>>>>> } >>>>>>>>> printf("%d",num); >>>>>>>>> >>>>>>>>> I think this will do. >>>>>>>>> >>>>>>>>> >>>>>>>>> On Sun, Aug 21, 2011 at 2:25 PM, sarvesh saran < >>>>>>>>> aquarian.thun...@gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Hi, >>>>>>>>>> >>>>>>>>>> I have a vector<int> A or an array (for C guys) that contains the >>>>>>>>>> octal representation of a number. >>>>>>>>>> >>>>>>>>>> So the array can be something like: [1,5,7] or [7,7,5,6,3,4,2] etc >>>>>>>>>> >>>>>>>>>> i.e no number in the array can be >= 8. >>>>>>>>>> >>>>>>>>>> Now given this array, I need to convert it its decimal >>>>>>>>>> representation. >>>>>>>>>> >>>>>>>>>> The naive way to do it would be to scan array from left to right, >>>>>>>>>> take each digit, multiply by 8 pow (x) where x is from 0 to ...n and >>>>>>>>>> compute >>>>>>>>>> sum. >>>>>>>>>> >>>>>>>>>> i.e something like: >>>>>>>>>> >>>>>>>>>> int oct = 1; >>>>>>>>>> int num = 0; >>>>>>>>>> >>>>>>>>>> for(<array length>){ >>>>>>>>>> num+= oct * A[i]; >>>>>>>>>> oct = oct * 8; >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> is there a faster way to do this? maybe using some STL container or >>>>>>>>>> algorithm. ? >>>>>>>>>> >>>>>>>>>> thanks, >>>>>>>>>> sarvesh >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> 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. >>>>>>>> >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>> >>>>> >>>>> -- >>>>> 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. >>>> >>> >>> -- >>> 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. >> > > -- > 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.