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.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var