Convert Int array to an integer
Is there anyway we can make an integer array to an integer
Thank you
Yes. Can you be more specific about what you wish to do?
Of course
IF we have an integer array such as int A[3] = {1,2,3}
How do we make it int A = 123.
Thanks
Remember your basic math. This is kind of the opposite of logarithm -- each element is multiplied by a power of ten.
123 = 1×10
2 + 2×10
1 + 3×10
0
Another example:
7926 = 7×10
3 + 9×10
2 + 2×10
1 + 6×10
0
The simplest way for your array is an iterative approach:
1 2 3 4
|
result = 0
for each element in array, first to last:
result *= 10
result += element
|
Hope this helps.
Topic archived. No new replies allowed.