Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static char[] IntToCharArray(int input)
- {
- short len = 0; //Number of places in the integer
- if(input < 10) len = 1;
- else if(input < 100) len = 2;
- else if (input < 1000) len = 3;
- else if (input < 10000) len = 4;
- else return null; // We just don't support those bigger numbers
- char[] output = new char[len];
- int input_copy = input;
- int i = 0;
- while (len > 0)
- {
- // 48 is just the offset in the ASCII table of the character
- // '0', so if we add 0-9 to that index, we can get the
- //characters for 0-9.
- output[i++] = (char)(48+(input%10));
- input-=(10^len);
- len--;
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement