Updated on Kisan Patel
To convert a number to its equivalent string representation in a specified base, you need to use Convert.ToString method as shown in below snippet code:
class Program { static void Main(string[] args) { int number1 = 2; int number2 = 74; int number3 = 110; int number4 = 4607; Console.WriteLine("base2 = " + Convert.ToString(number1, 2)); Console.WriteLine("base8 = " + Convert.ToString(number2, 8)); Console.WriteLine("base10 = " + Convert.ToString(number3, 10)); Console.WriteLine("base16 = " + Convert.ToString(number4, 16)); Console.ReadKey(); } }
Output of the above program…