Convert byte value to its base 2(Binary), base 8(Octal) and base 16(Hex) forms in CSharp
Description
The following code shows how to convert byte value to its base 2(Binary), base 8(Octal) and base 16(Hex) forms.
Example
//from w w w. j a va 2s .c om
using System;
public class Example
{
public static void Main()
{
byte[] numbers ={ 0, 15, 100, 213 };
Console.WriteLine("{0} {1,8} {2,5} {3,5}","Value", "Binary", "Octal", "Hex");
foreach (byte number in numbers) {
Console.WriteLine("{0,5} {1,8} {2,5} {3,5}",
number, Convert.ToString(number, 2),
Convert.ToString(number, 8),
Convert.ToString(number, 16));
}
}
}
The code above generates the following result.