Class Hex
Helper class for converting between bytes and Hex encoded string values.
Inherited Members
Namespace: Hiero
Assembly: Hiero.dll
Syntax
public static class Hex
Methods
| Edit this page View SourceFromBytes(byte[])
Converts a blob of bytes into the corresponding hex encoded string.
Declaration
public static string FromBytes(byte[] bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | bytes | Blob of bytes to turn into Hex. |
Returns
| Type | Description |
|---|---|
| string | String value of the bytes in lowercase Hex. |
FromBytes(ReadOnlyMemory<byte>)
Converts a blob of bytes into the corresponding hex encoded string.
Declaration
public static string FromBytes(ReadOnlyMemory<byte> bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlyMemory<byte> | bytes | Blob of bytes to turn into Hex. |
Returns
| Type | Description |
|---|---|
| string | String value of the bytes in lowercase Hex. |
FromBytes(ReadOnlySpan<byte>)
Converts a blob of bytes into the corresponding hex encoded string, using a ReadOnlySpan for performance.
Declaration
public static string FromBytes(ReadOnlySpan<byte> bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | bytes | Blob of bytes to turn into Hex. |
Returns
| Type | Description |
|---|---|
| string | String value of the bytes in lowercase Hex. |
ToBytes(string)
Converts string values encoded in Hex into bytes.
Declaration
public static ReadOnlyMemory<byte> ToBytes(string hex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | hex | A string containing a series of characters in hexadecimal format. |
Returns
| Type | Description |
|---|---|
| ReadOnlyMemory<byte> | A blob of bytes decoded from the hex string. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If the input string is
. |
| ArgumentOutOfRangeException | If the string of characters is not valid Hex. |
TryDecode(ReadOnlySpan<char>, Span<byte>, out int)
Parses a hex encoded string into a byte array.
Declaration
public static bool TryDecode(ReadOnlySpan<char> hex, Span<byte> buffer, out int bytesWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<char> | hex | The Hex Value |
| Span<byte> | buffer | Span receiving the decoded bytes |
| int | bytesWritten | Number of bytes written into the span |
Returns
| Type | Description |
|---|---|
| bool | true if successful, false if the hex string is invalid or buffer is too small. |
TryEncode(ReadOnlySpan<byte>, Span<char>, out int)
Computes the hex representation of a byte array and writes it to a destination span.
Declaration
public static bool TryEncode(ReadOnlySpan<byte> bytes, Span<char> destination, out int charsWritten)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | bytes | Incoming Bytes |
| Span<char> | destination | Span that will Receive the lower case encoded hex char values |
| int | charsWritten | Number of characters written (in case the buffer is larger than needed) |
Returns
| Type | Description |
|---|---|
| bool |