Converts byte to string in a specified base in CSharp
Description
The following code shows how to converts byte to string in a specified base.
Example
/*ww w . j a v a2s. co m*/
using System;
using System.Globalization;
public class MainClass
{
public static void Main()
{
int[] bases = { 2, 8, 10, 16};
byte[] numbers = { 0, 12, 113, Byte.MaxValue};
foreach (int baseValue in bases)
{
Console.WriteLine("Base {0} conversion:", baseValue);
foreach (byte number in numbers)
{
Console.WriteLine("{0,-5} --> 0x{1}",number, Convert.ToString(number, baseValue));
}
}
}
}
The code above generates the following result.