Format integer as octal and binary numbers
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
int[] numbers = { -1, 111111, 22222222 };
Console.WriteLine("{0,8} {1,32} {2,11} {3,10}", "Value", "Binary", "Octal", "Hex");
foreach (int number in numbers) {
Console.WriteLine("{0,8} {1,32} {2,11} {3,10}",
number, Convert.ToString(number, 2),
Convert.ToString(number, 8),
Convert.ToString(number, 16));
}
}
}
/*
Value Binary Octal Hex
-1 11111111111111111111111111111111 37777777777 ffffffff
111111 11011001000000111 331007 1b207
22222222 1010100110001010110001110 124612616 153158e
*/
Related examples in the same category