Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Convert.ToString Method (Int64, Int32)

Converts the value of a 64-bit signed integer to its equivalent String representation in a specified base.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static string ToString (
	long value,
	int toBase
)
public static String ToString (
	long value, 
	int toBase
)
public static function ToString (
	value : long, 
	toBase : int
) : String

Parameters

value

A 64-bit signed integer.

toBase

The base of the return value, which must be 2, 8, 10, or 16.

Return Value

The String representation of value in base toBase.

Exception typeCondition

ArgumentException

toBase is not 2, 8, 10, or 16.

The following code example converts several 64-bit integers to String s with the ToString method in the radixes supported by the method.

// Example of the Convert.ToString( long, int ) method.
using System;

class ConvertRadixLongDemo
{
    static void RunToStringDemo( )
    {
        long[ ] values = {
            long.MinValue,
            -112233445566778899, 
            4294967296, 
            999999999999999999, 
            long.MaxValue };
        int[ ]  radices = { 2, 8, 10, 16 };

        // Iterate through the values array.
        foreach( long value in values )
        {
            // Iterate through the radices.
            foreach( int radix in radices )
            {
                // Convert a value with a radix.
                string valueString = 
                    Convert.ToString( value, radix );

                // Display the results; use two lines, if necessary.
                if( valueString.Length > 50 )
                    Console.WriteLine( 
                        "{0,20} {1,3} \n          {2}", 
                        value, radix, valueString );
                else
                    Console.WriteLine( "{0,20} {1,3}   {2}", 
                        value, radix, valueString );
            }
        }
    } 

    static void Main( )
    {
        Console.WriteLine(
            "This example of Convert.ToString( long, int ) " +
            "generates \nthe following output. It converts several " +
            "long values to \nstrings using the radixes supported " +
            "by the method." );
        Console.WriteLine( 
            "\n          Value      Radix     String" +
            "\n          -----      -----     ------" );

        RunToStringDemo( );
    } 
} 

/*
This example of Convert.ToString( long, int ) generates
the following output. It converts several long values to
strings using the radixes supported by the method.

          Value      Radix     String
          -----      -----     ------
-9223372036854775808   2
          1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808   8   1000000000000000000000
-9223372036854775808  10   -9223372036854775808
-9223372036854775808  16   8000000000000000
 -112233445566778899   2
          1111111001110001010001000100011010100001000100101111000111101101
 -112233445566778899   8   1771612104324104570755
 -112233445566778899  10   -112233445566778899
 -112233445566778899  16   fe714446a112f1ed
          4294967296   2   100000000000000000000000000000000
          4294967296   8   40000000000
          4294967296  10   4294967296
          4294967296  16   100000000
  999999999999999999   2
          110111100000101101101011001110100111011000111111111111111111
  999999999999999999   8   67405553164730777777
  999999999999999999  10   999999999999999999
  999999999999999999  16   de0b6b3a763ffff
 9223372036854775807   2
          111111111111111111111111111111111111111111111111111111111111111
 9223372036854775807   8   777777777777777777777
 9223372036854775807  10   9223372036854775807
 9223372036854775807  16   7fffffffffffffff
*/

// Example of the Convert.ToString( long, int ) method.
import System.* ;

class ConvertRadixLongDemo
{   
    static void RunToStringDemo()
    {
        long values[] = { Long.MIN_VALUE, -112233445566778899L, 4294967296L,
                        999999999999999999L, Long.MAX_VALUE    };
        int radices[] =  { 2, 8, 10, 16 };

        // Iterate through the values array.
        for (int iCtr = 0; iCtr < values.length; iCtr++)    {
            long value = values[iCtr];

            // Iterate through the radices
            for (int iCtr1 = 0; iCtr1 < radices.length; iCtr1++)
            {
                int radix = radices[iCtr1];

                // Iterate through the radices.
                // Convert a value with a radix.
                String valueString = Convert.ToString(value, radix);

                // Display the results; use two lines, if necessary.
                if (valueString.get_Length() > 50) {
                    Console.WriteLine("{0,20} {1,3} \n          {2}", 
                        System.Convert.ToString(value), 
                        System.Convert.ToString(radix), valueString);
                }
                else {
                    Console.WriteLine("{0,20} {1,3}   {2}", 
                        System.Convert.ToString(value), 
                        System.Convert.ToString(radix), valueString);
                }
            }
        }
    } //RunToStringDemo   

    public static void main(String[] args)
    {
        Console.WriteLine(("This example of Convert.ToString( long, int ) " 
            + "generates \nthe following output. It converts several " 
            + "long values to \nstrings using the radixes supported " 
            + "by the method."));
        Console.WriteLine(("\n          Value      Radix     String" 
            + "\n          -----      -----     ------"));

        RunToStringDemo();
    } //main
} //ConvertRadixLongDemo

/*
This example of Convert.ToString( long, int ) generates
the following output. It converts several long values to
strings using the radixes supported by the method.

          Value      Radix     String
          -----      -----     ------
-9223372036854775808   2
          1000000000000000000000000000000000000000000000000000000000000000
-9223372036854775808   8   1000000000000000000000
-9223372036854775808  10   -9223372036854775808
-9223372036854775808  16   8000000000000000
 -112233445566778899   2
          1111111001110001010001000100011010100001000100101111000111101101
 -112233445566778899   8   1771612104324104570755
 -112233445566778899  10   -112233445566778899
 -112233445566778899  16   fe714446a112f1ed
          4294967296   2   100000000000000000000000000000000
          4294967296   8   40000000000
          4294967296  10   4294967296
          4294967296  16   100000000
  999999999999999999   2
          110111100000101101101011001110100111011000111111111111111111
  999999999999999999   8   67405553164730777777
  999999999999999999  10   999999999999999999
  999999999999999999  16   de0b6b3a763ffff
 9223372036854775807   2
          111111111111111111111111111111111111111111111111111111111111111
 9223372036854775807   8   777777777777777777777
 9223372036854775807  10   9223372036854775807
 9223372036854775807  16   7fffffffffffffff
*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft