Windows Dev Center

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)

'Declaration
Public Shared Function ToString ( _
	value As Long, _
	toBase As Integer _
) As String

Parameters

value
Type: System.Int64
A 64-bit signed integer.
toBase
Type: System.Int32
The base of the return value, which must be 2, 8, 10, or 16.

Return Value

Type: System.String
The String representation of value in base toBase.

ExceptionCondition
ArgumentException

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

If value is negative and toBase is a non-decimal value, the returned string uses two's complement representation.

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, Integer ) method.

Module Example

   Sub RunToStringDemo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      Dim values As Long() = { _
          Long.MinValue, _
          -112233445566778899, _
          4294967296, _
          999999999999999999, _
          Long.MaxValue}
      Dim radices As Integer() = {2, 8, 10, 16}

      ' Iterate through the values array.
      Dim value As Long
      For Each value In values

         ' Iterate through the radices.
         Dim radix As Integer
         For Each radix In radices

            ' Convert a value with a radix.
            Dim valueString As String = _
                Convert.ToString(value, radix)

            ' Display the results; use two lines, if necessary.
            If valueString.Length > 50 Then
               outputBlock.Text &= String.Format("{0,20} {1,3} " & _
                   vbCrLf & "          {2}", _
                   value, radix, valueString) & vbCrLf
            Else
               outputBlock.Text &= String.Format("{0,20} {1,3}   {2}", _
                   value, radix, valueString) & vbCrLf
            End If
         Next radix
      Next value
   End Sub

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      outputBlock.Text &= String.Format( _
          "This example of Convert.ToString( Long, Integer ) " & _
          "generates " & vbCrLf & "the following output. It " & _
          "converts several Long values to " & vbCrLf & "strings " & _
          "using the radixes supported by the method.") & vbCrLf
      outputBlock.Text &= String.Format(vbCrLf & _
          "          Value      Radix     String" & vbCrLf & _
          "          -----      -----     ------") & vbCrLf

      RunToStringDemo(outputBlock)

   End Sub
End Module

' This example of Convert.ToString( Long, Integer ) 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 Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft