Convert.ToString Converts the value of a 32-bit signed integer to its equivalent string representation in a specified base.
using System;
public class MainClass
{
public static void Main()
{
int[] bases = { 2, 8, 10, 16 };
int[] numbers = { Int32.MinValue, -123, -12345, -18, 12, 19, Int32.MaxValue };
foreach (int baseValue in bases)
{
Console.WriteLine("Base {0} conversion:", baseValue);
foreach (int number in numbers)
{
Console.WriteLine(" {0,-15} --> 0x{1}", number, Convert.ToString(number, baseValue));
}
}
}
}
Related examples in the same category