[algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread sarvesh saran
Hi,

I have a vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
int num = 0;
for(int i=0;iA.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.comwrote:

 Hi,

 I have a vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
int num = 0;
for(int i=0;iA.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.comwrote:

 int num = 0;
 for(int i=0;iA.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 vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread sarvesh saran
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.comwrote:

 int num = 0;
 for(int i=0;iA.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.comwrote:

 int num = 0;
 for(int i=0;iA.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 vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Sanjay Rajpal
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.comwrote:

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

 int num = 0;
 for(int i=0;iA.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;iA.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 vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Prakash D
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;iA.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;iA.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 vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread sarvesh saran
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;iA.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;iA.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 vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
@sanjay, oops, my intention was bitwise OR

On Sun, Aug 21, 2011 at 4:25 PM, sarvesh saran
aquarian.thun...@gmail.comwrote:

 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;iA.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;iA.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 vectorint 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.



Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Sanjay Rajpal
@Nitin : could u explain ur logic ?


Sanju
:)



On Sun, Aug 21, 2011 at 9:24 AM, Nitin Nizhawan nitin.nizha...@gmail.comwrote:

 @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;iA.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;iA.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 vectorint 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.
 

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
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.comwrote:

 @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.comwrote:

  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;iA.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;iA.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 vectorint 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, 

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Sanjay Rajpal
ok. got it Nitin. thanx :)


Sanju
:)



On Sun, Aug 21, 2011 at 10:06 AM, Nitin Nizhawan
nitin.nizha...@gmail.comwrote:

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

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

  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;iA.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;iA.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 vectorint 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 

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Anantha Krishnan
Hi Sarvesh,

For this problem this is my solution.

A=[1,5,6]
n=len(A)
Ans=[0,1,1,2,1,2,2,3]
count=0
for i in range(0,n):
count=count+Ans[A[i]]
print count

Is there any flaw?

Thanks  Regards,
Anantha Krishnan

On Sun, Aug 21, 2011 at 4:25 PM, sarvesh saran
aquarian.thun...@gmail.comwrote:

 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;iA.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;iA.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 vectorint 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 

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Sanjay Rajpal
This will print the no. of bits set, not the decimal equivalent of the
number.


Sanju
:)



On Sun, Aug 21, 2011 at 11:18 AM, Anantha Krishnan 
ananthakrishnan@gmail.com wrote:

 Hi Sarvesh,

 For this problem this is my solution.

  A=[1,5,6]
 n=len(A)
 Ans=[0,1,1,2,1,2,2,3]
 count=0
 for i in range(0,n):
 count=count+Ans[A[i]]
 print count

 Is there any flaw?

 Thanks  Regards,
 Anantha Krishnan

 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;iA.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;iA.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 vectorint 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 

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread sarvesh saran
Hi Anantha,

No. that makes sense. thanks!

I am now trying to solve a really tricky problem. It can be found here:
http://stackoverflow.com/questions/5370134/interesting-programming-interview-question

A user called Xanatos has given a solution but i cannot make any sense of
it.

-sarvesh

On Sun, Aug 21, 2011 at 11:48 PM, Anantha Krishnan 
ananthakrishnan@gmail.com wrote:

 Hi Sarvesh,

 For this problem this is my solution.

 A=[1,5,6]
 n=len(A)
 Ans=[0,1,1,2,1,2,2,3]
 count=0
 for i in range(0,n):
 count=count+Ans[A[i]]
 print count

 Is there any flaw?

 Thanks  Regards,
 Anantha Krishnan

 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;iA.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;iA.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 vectorint 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