question about arrays

This is a discussion on question about arrays within the C++ Programming forums, part of the General Programming Boards category; Hello, Iím new to programming so bare with me . Is there a way to individual input an int number ...

  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 10: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, 06: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, 11:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 01:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 03:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21