Thread: question about arrays

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    4

    question about arrays

    Hello, I’m new to programming so bare with me . Is there a way to individual input an int number into an array so that each digit would be in its own index? I know strings work this way but I can’t find anything about numbers working this way.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Not directly, but you can write code to extract one digit at a time from the number. It involves using the % and / operators.

    Edit: I'm assuming you're talking about base 10 digits. Since the numbers are stored internally as a sequence of bits, there's no way to extract base 10 digits directly from that. However, if you wanted to extract binary, or octal, or hexadecimal digits, you could do that directly using bitwise operators. If you want to do it for a base that's not a power of two, you would use the method I alluded to above.
    Last edited by robatino; 05-05-2007 at 09:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 05:32 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 08:24 PM
  3. Replies: 6
    Last Post: 04-26-2004, 10:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 12:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 02:40 PM