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.

Printable View

- 05-05-2007nevh158question 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.

- 05-05-2007robatino
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.