Converting an Integer Array to an Integer

I have an array of integers that I need to convert to a single integer. Is there a function built into C++ that I can use to do so? If so, what is it called and how is it implemented?

If not, could someone please walk me through the logic of how that function would work?

Thanks in advance.
What does that mean? Can you provide an example of what you want?
In other words, I have a 16 digit integer array:

1|2|3|4|5|6|7|8|9|0|1|2|3|4|5|6

and I need to get it into a single number

1234567890123456

I realized that an int is too small a type to hold 16 digits, so I went with a double

I tried the following in a function with a call from main():

---------------

int temp = 0;
double number = 0;


for(int i=0; i<16; i++)
{
temp = array[i];
number += temp;
number *= 10;
}

return number;

-------------

Should work, right? Nope...
There are several ways to do so:

1. string way: use a stringstream to convert first to a string by adding and so on.
2. math way: use your knowledge about p-adic representation of numbers
means:
sum(i = 0 to 15) { a_i * p^i } = number

and your a_i are your values in the array (a[i])
and p is in your case 10, because it is decimal base.

1
2
3
double total(0);
for (int i = 0; i < 16; i++)
   total += a[i]*pow(10,i);


EDIT: wow, stop. why didnt it work? i just now realized your chunk of code. But you didnt use any code tags.. What's the error?
Last edited on
Topic archived. No new replies allowed.