Convert.FromHexString Method

Definition

Overloads

FromHexString(ReadOnlySpan<Char>)

Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.

FromHexString(String)

Converts the specified string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.

FromHexString(ReadOnlySpan<Char>, Span<Byte>, Int32, Int32)

Converts the span of chars, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer span.

FromHexString(String, Span<Byte>, Int32, Int32)

Converts the string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer span.

FromHexString(ReadOnlySpan<Char>)

Source:
Convert.cs
Source:
Convert.cs
Source:
Convert.cs

Converts the span, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.

C#
public static byte[] FromHexString (ReadOnlySpan<char> chars);

Parameters

chars
ReadOnlySpan<Char>

The span to convert.

Returns

Byte[]

An array of 8-bit unsigned integers that is equivalent to chars.

Exceptions

The length of chars, is not zero or a multiple of 2.

The format of chars is invalid. chars contains a non-hex character.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9

FromHexString(String)

Source:
Convert.cs
Source:
Convert.cs
Source:
Convert.cs

Converts the specified string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer array.

C#
public static byte[] FromHexString (string s);

Parameters

s
String

The string to convert.

Returns

Byte[]

An array of 8-bit unsigned integers that is equivalent to s.

Exceptions

The length of s, is not zero or a multiple of 2.

The format of s is invalid. s contains a non-hex character.

Applies to

.NET 9 and other versions
Product Versions
.NET 5, 6, 7, 8, 9

FromHexString(ReadOnlySpan<Char>, Span<Byte>, Int32, Int32)

Source:
Convert.cs

Converts the span of chars, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer span.

C#
public static System.Buffers.OperationStatus FromHexString (ReadOnlySpan<char> source, Span<byte> destination, out int charsConsumed, out int bytesWritten);

Parameters

source
ReadOnlySpan<Char>

The span to convert.

destination
Span<Byte>

The span in which to write the converted 8-bit unsigned integers. When this method returns value different than Done, either the span remains unmodified or contains an incomplete conversion of source, up to the last valid character.

charsConsumed
Int32

When this method returns, contains the number of characters that were consumed from source.

bytesWritten
Int32

When this method returns, contains the number of bytes that were written to destination.

Returns

An OperationStatus describing the result of the operation.

Applies to

.NET 9
Product Versions
.NET 9

FromHexString(String, Span<Byte>, Int32, Int32)

Source:
Convert.cs

Converts the string, which encodes binary data as hex characters, to an equivalent 8-bit unsigned integer span.

C#
public static System.Buffers.OperationStatus FromHexString (string source, Span<byte> destination, out int charsConsumed, out int bytesWritten);

Parameters

source
String

The string to convert.

destination
Span<Byte>

The span in which to write the converted 8-bit unsigned integers. When this method returns value different than Done, either the span remains unmodified or contains an incomplete conversion of source, up to the last valid character.

charsConsumed
Int32

When this method returns, contains the number of characters that were consumed from source.

bytesWritten
Int32

When this method returns, contains the number of bytes that were written to destination.

Returns

An OperationStatus describing the result of the operation.

Exceptions

Passed string source is null.

Applies to

.NET 9
Product Versions
.NET 9