Convert Int array to an integer
Nov 23, 2013 at 2:38am
Is there anyway we can make an integer array to an integer
Thank you
Nov 23, 2013 at 2:46am
Yes. Can you be more specific about what you wish to do?
Nov 23, 2013 at 2:48am
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
Nov 23, 2013 at 2:53am
Nov 23, 2013 at 2:57am
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.