C# BitConverter ToString(Byte[], Int32, Int32)
Description
BitConverter ToString(Byte[], Int32, Int32)
converts
the numeric value of each element of a specified subarray of bytes to its equivalent
hexadecimal string representation.
Syntax
BitConverter.ToString(Byte[], Int32, Int32)
has the following syntax.
public static string ToString(
byte[] value,// ww w. ja v a2 s . c om
int startIndex,
int length
)
Parameters
BitConverter.ToString(Byte[], Int32, Int32)
has the following parameters.
value
- An array of bytes.startIndex
- The starting position within value.length
- The number of array elements in value to convert.
Returns
BitConverter.ToString(Byte[], Int32, Int32)
method returns A string of hexadecimal pairs separated by hyphens, where each pair represents
the corresponding element in a subarray of value; for example, "7F-2C-4A-00".
Example
The following example uses the ToString method to convert part of a byte array, starting at the specified startIndex and with the specified length, to a string.
using System;//from w w w .j a va 2 s . c o m
class BytesToStringDemo
{
public static void Main( )
{
byte[ ] bytes = {
170, 170, 170, 170, 170, 0, 0, 232, 137, 4,
35, 199, 138, 255, 232, 244, 255, 252, 205, 255,
255, 129 };
Console.WriteLine(BitConverter.ToString( bytes, 2, 5 ) );
}
}
The code above generates the following result.