Convert.ToString Method (Byte, Int32)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Converts the value of an 8-bit unsigned integer to its equivalent string representation in a specified base.
Assembly: mscorlib (in mscorlib.dll)
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.
| Exception | Condition |
|---|---|
| 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, int ) method. using System; class Example { static void RunToStringDemo(System.Windows.Controls.TextBlock outputBlock) { byte[] values = { byte.MinValue, 13, byte.MaxValue }; int[] radices = { 2, 8, 10, 16 }; // Iterate through the values array. foreach (byte value in values) { // Iterate through the radices. foreach (int radix in radices) { // Convert a value with a radix. string valueString = Convert.ToString(value, radix); outputBlock.Text += String.Format("{0,7} {1,3} {2}", value, radix, valueString) + "\n"; } } } public static void Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += String.Format( "This example of Convert.ToString( byte, int ) " + "generates \nthe following output. It converts several " + "byte values to \nstrings using the radixes supported " + "by the method.") + "\n"; outputBlock.Text += String.Format( "\n Value Radix String" + "\n ----- ----- ------") + "\n"; RunToStringDemo(outputBlock); } } /* This example of Convert.ToString( byte, int ) 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 */
Show: