Converts a string of hex digits into a byte array.

Namespace: CardWerk.SmartCard.Util
Assembly: CardWerk.SmartCard (in CardWerk.SmartCard.dll)

Public Shared Function ToByteArray( _ 
ByVal sHex As String
) As Byte()
This language is not supported or no code example is available.
public static byte[] ToByteArray( 
string sHex 
)
This language is not supported or no code example is available.
public:  
static array< Byte >^ ToByteArray( 
String^ sHex 
)
This language is not supported or no code example is available.
public static function ToByteArray( 
sHex : String 
) : byte[];
This language is not supported or no code example is available.

Parameters

sHex
Type: string

String of hex digits. This string must not be null and must have an even length. If it is null, then an ArgumentNullException will be thrown. The hex digits may be upper or lower case. If it is not of even length or contains characters that are not valid hex digits, then an ArgumentException will be thrown.

Return Value

Type: byte[]

Returns a byte array with the byte values of every pair of hex digits in the input string. If the given input string is empty, then the returned byte array is an empty array, too. Generally the size of the returned byte array is half the size of the input string.

Exception type Condition

ArgumentException

Thrown when one or more arguments have unsupported or illegal values.

.NET Framework

Supported in: 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

.NET Core

Supported in: 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0

.NET Standard

Supported in: 2.0