C# BitConverter ToString(Byte[], Int32)

Description

BitConverter ToString(Byte[], 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) has the following syntax.


public static string ToString(
  byte[] value,
  int startIndex
)

Parameters

BitConverter.ToString(Byte[], Int32) has the following parameters.

  • value - An array of bytes.
  • startIndex - The starting position within value.

Returns

BitConverter.ToString(Byte[], 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 code example converts the part of a Byte array starting at the specified startIndex to a String with the ToString method.


using System;//from  ww w  .j a  v  a2s.c  o m

class BytesToStringDemo
{
    public static void Main( )
    {

        byte[ ] bytes = {
              0, 222,   0,   0,   0, 224, 111,  64,   0,   0, 
            224, 255, 255, 255, 239,  65,   0,   0, 131,   0, 
             91,   0,   0, 240, 255,   0,   0, 240, 157 };

        Console.WriteLine( BitConverter.ToString( bytes, 2 ) );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version