Export (0) Print
Expand All

Convert.ToString Method (Byte, Int32)

Converts the value of an 8-bit unsigned integer to its equivalent string representation in a specified base.

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

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function ToString ( _
	value As Byte, _
	toBase As Integer _
) As String

Parameters

value
Type: System.Byte
An 8-bit unsigned 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.

The following code example converts several Byte values to String s with the ToString method in the radixes supported by the method.


' Example of the Convert.ToString( Byte, Integer ) method.

Module Example

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

      Dim values As Byte() = { _
          Byte.MinValue, _
          13, _
          Byte.MaxValue}
      Dim radices As Integer() = {2, 8, 10, 16}

      ' Iterate through the values array.
      Dim value As Byte
      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)

            outputBlock.Text &= String.Format("{0,7}  {1,3}    {2}", _
                value, radix, valueString) & vbCrLf
         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( Byte, Integer ) " & _
          "generates " & vbCrLf & "the following output. It " & _
          "converts several Byte 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( Byte, Integer ) generates
' the following output. It converts several Byte values to
' strings using the radixes supported by the method.
' 
'   Value  Radix  String
'   -----  -----  ------
'       0    2    0
'       0    8    0
'       0   10    0
'       0   16    0
'      13    2    1101
'      13    8    15
'      13   10    13
'      13   16    d
'     255    2    11111111
'     255    8    377
'     255   10    255
'     255   16    ff


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft