C# Convert ToString(Int64, Int32)
Description
Convert ToString(Int64, Int32)
converts the value of
a 64-bit signed integer to its equivalent string representation in a specified
base.
Syntax
Convert.ToString(Int64, Int32)
has the following syntax.
public static string ToString(
long value,
int toBase
)
Parameters
Convert.ToString(Int64, Int32)
has the following parameters.
value
- The 64-bit signed integer to convert.toBase
- The base of the return value, which must be 2, 8, 10, or 16.
Returns
Convert.ToString(Int64, Int32)
method returns The string representation of value in base toBase.
Example
The following example converts each element in a long integer array to its equivalent binary, hexadecimal, decimal, and hexadecimal string representations.
/*ww w . j av a 2 s.c o m*/
using System;
public class MainClass{
public static void Main(String[] argv){
int[] bases = { 2, 8, 10, 16};
long[] numbers = { Int64.MinValue, -123123123, -123123, -18, 12,
123123123, Int64.MaxValue };
foreach (int baseValue in bases)
{
Console.WriteLine("Base {0} conversion:", baseValue);
foreach (long number in numbers)
{
Console.WriteLine(" {0,-23} --> 0x{1}",
number, Convert.ToString(number, baseValue));
}
}
}
}
The code above generates the following result.