private static readonly char[] base16Values = new char[16]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
private static char[] maxCharIntBase2 = new char[33];
public static void Main()
for (int i = -20; i <= 100; i++)
for (int j = 2; j <= 16; j++)
Console.WriteLine("ITOA RESULT: " + itoa(i, j));
static string itoa(int value, int numericBase)
if (numericBase < 2 || numericBase > 16)
Console.WriteLine("Attempted to convert an int to a string with a numeric base less than 2 or greater than 16");
maxCharIntBase2[--i] = base16Values[-(value % numericBase)];
value = -(value / numericBase);
maxCharIntBase2[--i] = base16Values[value % numericBase];
maxCharIntBase2[--i] = '-';
return new string (maxCharIntBase2, i, 33 - i);