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.
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.
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.