Thread: converting Int array to a single int

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    120

    converting Int array to a single int

    Hi

    i wanted to know how to convert an array of ints to a single int, for example:

    Code:
    //I want to convert this:
    int a[20]={4,2,4,5,6,1,2};
    //to this:
    int c=4245612;
    how can i do that?? help pls

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Did you forget how the decimal system works?

    Each place is a power of 10, simply multiply each element by 10 to its respective place. So,

    Code:
    {4,2,4,5,6,1,2} = (10^6 * 4) + (10^5 * 2) + (10^4 * 4) + (10^3 * 5) + (10^2 * 6) + (10^1 * 1) + (10^0 * 2)
    Or put all the numbers in a string, and parse it out.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    120
    Tks man solved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can anyone help?
    By javalurnin in forum C Programming
    Replies: 11
    Last Post: 12-02-2009, 06:02 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM