Table of Contents

Class ByteArrayExtensions

Namespace
Plugin.ByteArrays
Assembly
Plugin.ByteArrays.dll

Functions converting other types into a byte array.

public static class ByteArrayExtensions
Inheritance
ByteArrayExtensions
Inherited Members

Methods

BitReverse(byte[])

Reverses the bits in each byte of the array.

public static byte[] BitReverse(this byte[] array)

Parameters

array byte[]

The byte array to process.

Returns

byte[]

A new byte array with bits reversed in each byte.

CalculateCrc32(byte[])

Calculates the CRC32 checksum of the byte array.

public static uint CalculateCrc32(this byte[] array)

Parameters

array byte[]

The byte array to calculate checksum for.

Returns

uint

The CRC32 checksum as a 32-bit unsigned integer.

CalculateMd5(byte[])

Calculates the MD5 hash of the byte array. Note: MD5 is considered cryptographically broken and should not be used for security purposes.

public static byte[] CalculateMd5(this byte[] array)

Parameters

array byte[]

The byte array to hash.

Returns

byte[]

The MD5 hash as a byte array.

CalculateSha1(byte[])

Calculates the SHA-1 hash of the byte array. Note: SHA-1 is considered weak and should not be used for security-critical applications.

public static byte[] CalculateSha1(this byte[] array)

Parameters

array byte[]

The byte array to hash.

Returns

byte[]

The SHA-1 hash as a byte array.

CalculateSha256(byte[])

Calculates the SHA-256 hash of the byte array.

public static byte[] CalculateSha256(this byte[] array)

Parameters

array byte[]

The byte array to hash.

Returns

byte[]

The SHA-256 hash as a byte array.

Concatenate(params byte[][])

Concatenates multiple byte arrays efficiently.

public static byte[] Concatenate(params byte[][] arrays)

Parameters

arrays byte[][]

The byte arrays to concatenate.

Returns

byte[]

A new byte array containing all input arrays concatenated.

EndsWith(byte[], byte[])

Determines whether the byte array ends with the specified pattern. This method is case-sensitive and culture-insensitive.

public static bool EndsWith(this byte[] array, byte[] pattern)

Parameters

array byte[]

The byte array to check.

pattern byte[]

The pattern to check for at the end of the array.

Returns

bool

True if the array ends with the specified pattern; otherwise, false.

FromBase64String(string)

Converts a Base64 string to a byte array.

public static byte[] FromBase64String(string base64String)

Parameters

base64String string

The Base64 string to convert.

Returns

byte[]

A byte array representation.

Exceptions

FormatException

Thrown when the Base64 string is invalid.

FromHexString(string)

Converts a hex string back to a byte array.

public static byte[] FromHexString(string hexString)

Parameters

hexString string

The hex string to convert.

Returns

byte[]

A byte array representation of the hex string.

Exceptions

ArgumentException

Thrown when the hex string is invalid.

GetBit(byte[], int)

Gets the value of a specific bit at the given position.

public static bool GetBit(this byte[] array, int bitPosition)

Parameters

array byte[]

The byte array to read from.

bitPosition int

The bit position (0-based, where 0 is LSB of first byte).

Returns

bool

True if the bit is set, false otherwise.

IndexOf(byte[], byte[])

Finds the first occurrence of a pattern in a byte array.

public static int IndexOf(this byte[] array, byte[] pattern)

Parameters

array byte[]

The array to search in.

pattern byte[]

The pattern to search for.

Returns

int

The index of the first occurrence, or -1 if not found.

IndexOfAll(byte[], byte[])

Searches for all occurrences of a byte pattern in the array. Returns an array of indices where the pattern is found.

public static int[] IndexOfAll(this byte[] array, byte[] pattern)

Parameters

array byte[]

The source array to search in.

pattern byte[]

The pattern to search for.

Returns

int[]

An array of indices where the pattern occurs.

IsIdenticalTo(byte[]?, byte[]?)

Checks if two byte arrays are identical in content and length. Uses reference equality and null checks for performance and correctness.

public static bool IsIdenticalTo(this byte[]? a1, byte[]? a2)

Parameters

a1 byte[]

First byte array.

a2 byte[]

Second byte array.

Returns

bool

True if arrays are identical; otherwise, false.

Pad(byte[], int, byte, bool)

Pads the byte array to the specified length with the given padding byte.

public static byte[] Pad(this byte[] array, int totalLength, byte paddingByte = 0, bool padLeft = false)

Parameters

array byte[]

The source array to pad.

totalLength int

The desired total length.

paddingByte byte

The byte to use for padding (default is 0).

padLeft bool

True to pad on the left, false to pad on the right.

Returns

byte[]

A new padded byte array.

RemovePadding(byte[], byte, bool)

Removes padding from the byte array.

public static byte[] RemovePadding(this byte[] array, byte paddingByte = 0, bool fromLeft = false)

Parameters

array byte[]

The padded array.

paddingByte byte

The padding byte to remove (default is 0).

fromLeft bool

True to remove padding from the left, false from the right.

Returns

byte[]

A new byte array with padding removed.

Reverse(byte[])

Reverses the byte array and returns a new array.

public static byte[] Reverse(this byte[] array)

Parameters

array byte[]

The byte array to reverse.

Returns

byte[]

A new byte array with elements in reverse order.

SafeSlice(byte[], int, int)

Safely slices a byte array without throwing exceptions.

public static byte[] SafeSlice(this byte[] array, int start, int length)

Parameters

array byte[]

The source array.

start int

The starting index.

length int

The number of bytes to take.

Returns

byte[]

A new byte array containing the sliced data, or empty array if parameters are invalid.

SetBit(byte[], int)

Sets a specific bit at the given position to 1.

public static byte[] SetBit(this byte[] array, int bitPosition)

Parameters

array byte[]

The byte array to modify.

bitPosition int

The bit position (0-based, where 0 is LSB of first byte).

Returns

byte[]

A new byte array with the bit set.

Split(byte[], int)

Splits the byte array into chunks of the specified size.

public static IEnumerable<byte[]> Split(this byte[] array, int chunkSize)

Parameters

array byte[]

The source array to split.

chunkSize int

The size of each chunk.

Returns

IEnumerable<byte[]>

An enumerable of byte arrays representing the chunks.

SplitAt(byte[], byte)

Splits the byte array at the specified delimiter.

public static IEnumerable<byte[]> SplitAt(this byte[] array, byte delimiter)

Parameters

array byte[]

The source array to split.

delimiter byte

The delimiter byte.

Returns

IEnumerable<byte[]>

An enumerable of byte arrays split at the delimiter.

StartsWith(byte[], byte[])

Checks if a byte array starts with a specific pattern.

public static bool StartsWith(this byte[] array, byte[] pattern)

Parameters

array byte[]

The array to check.

pattern byte[]

The pattern to look for.

Returns

bool

True if the array starts with the pattern, false otherwise.

ToAsciiString(byte[], int, int)

Converts parts of a byte array into an ASCII String.

public static string ToAsciiString(this byte[] array, int position = 0, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of characters of the expected string

Returns

string

Converted value.

ToAsciiString(byte[], ref int, int)

Converts parts of a byte array into an ASCII String.

public static string ToAsciiString(this byte[] array, ref int position, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of characters of the expected string

Returns

string

Converted value.

ToAsciiStringOrDefault(byte[], int, int, string)

Converts parts of a byte array into an ASCII String.

public static string ToAsciiStringOrDefault(this byte[] array, int position = 0, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of characters of the expected string

defaultValue string

Default value for that type, can be overriden.

Returns

string

Converted value.

ToAsciiStringOrDefault(byte[], ref int, int, string)

Converts parts of a byte array into an ASCII String.

public static string ToAsciiStringOrDefault(this byte[] array, ref int position, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of characters of the expected string

defaultValue string

Default value for that type, can be overriden.

Returns

string

Converted value.

ToBase64String(byte[])

Converts a byte array to a Base64 string.

public static string ToBase64String(this byte[] array)

Parameters

array byte[]

The byte array to convert.

Returns

string

A Base64 string representation.

ToBoolean(byte[], int)

Converts the byte array into a Boolean value True[1] or False[0]. Size = 1 byte.

public static bool ToBoolean(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

bool

Converted value.

ToBoolean(byte[], ref int)

Converts the byte array into a Boolean value True[1] or False[0]. Size = 1 byte.

public static bool ToBoolean(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

bool

Converted value.

ToBooleanOrDefault(byte[], int, bool)

Converts the byte array into a Boolean value True[1] or False[0]. Returns defaultValue if array too short Size = 1 byte.

public static bool ToBooleanOrDefault(this byte[] array, int position = 0, bool defaultValue = false)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue bool

Default value for that type, can be overriden.

Returns

bool

Converted value.

ToBooleanOrDefault(byte[], ref int, bool)

Converts the byte array into a Boolean value True[1] or False[0]. Returns defaultValue if array too short Size = 1 byte.

public static bool ToBooleanOrDefault(this byte[] array, ref int position, bool defaultValue = false)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue bool

Default value for that type, can be overriden.

Returns

bool

Converted value.

ToByte(byte[], int)

Converts the byte array into an Unsigned 8-bit integer From 0 to 255. Size = 1 byte.

public static byte ToByte(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

byte

Converted value.

ToByte(byte[], ref int)

Converts the byte array into an Unsigned 8-bit integer From 0 to 255. Size = 1 byte.

public static byte ToByte(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

byte

Converted value.

ToByteOrDefault(byte[], int, byte)

Converts the byte array into an Unsigned 8-bit integer From 0 to 255. Size = 1 byte.

public static byte ToByteOrDefault(this byte[] array, int position = 0, byte defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue byte

Value returned if out of bounds

Returns

byte

Converted value.

ToByteOrDefault(byte[], ref int, byte)

Converts the byte array into an Unsigned 8-bit integer From 0 to 255. Size = 1 byte.

public static byte ToByteOrDefault(this byte[] array, ref int position, byte defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue byte

Value returned if out of bounds

Returns

byte

Converted value.

ToChar(byte[], int)

Converts the byte array into a Character in UTF-16 code unit Any UTF-16 character. Size = 2 bytes.

public static char ToChar(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

char

Converted value.

ToChar(byte[], ref int)

Converts the byte array into a Character in UTF-16 code unit Any UTF-16 character. Size = 2 bytes.

public static char ToChar(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

char

Converted value.

ToCharOrDefault(byte[], int, char)

Converts the byte array into a Character in UTF-16 code unit Any UTF-16 character. Size = 2 bytes.

public static char ToCharOrDefault(this byte[] array, int position = 0, char defaultValue = '\0')

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue char

Default value for that type, can be overriden.

Returns

char

Converted value.

ToCharOrDefault(byte[], ref int, char)

Converts the byte array into a Character in UTF-16 code unit Any UTF-16 character. Size = 2 bytes.

public static char ToCharOrDefault(this byte[] array, ref int position, char defaultValue = '\0')

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue char

Default value for that type, can be overriden.

Returns

char

Converted value.

ToDateTime(byte[], int)

Converts the byte array into a DateTime using binary representation. Size = 8 bytes.

public static DateTime ToDateTime(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

DateTime

Converted DateTime value.

ToDateTime(byte[], ref int)

Converts the byte array into a DateTime using binary representation. Size = 8 bytes.

public static DateTime ToDateTime(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

DateTime

Converted DateTime value.

ToDateTimeFromUnixTimestamp(byte[], int)

Converts the byte array into a DateTime from Unix timestamp (seconds since epoch). Size = 4 bytes.

public static DateTime ToDateTimeFromUnixTimestamp(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

DateTime

Converted DateTime value.

ToDateTimeFromUnixTimestamp(byte[], ref int)

Converts the byte array into a DateTime from Unix timestamp (seconds since epoch). Size = 4 bytes.

public static DateTime ToDateTimeFromUnixTimestamp(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

DateTime

Converted DateTime value.

ToDateTimeFromUnixTimestampOrDefault(byte[], int, DateTime)

Converts the byte array into a DateTime from Unix timestamp (seconds since epoch). Returns the default value if conversion fails. Size = 4 bytes.

public static DateTime ToDateTimeFromUnixTimestampOrDefault(this byte[] array, int position = 0, DateTime defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue DateTime

Default value for that type, can be overridden.

Returns

DateTime

Converted DateTime value.

ToDateTimeFromUnixTimestampOrDefault(byte[], ref int, DateTime)

Converts the byte array into a DateTime from Unix timestamp (seconds since epoch). Returns the default value if conversion fails. Size = 4 bytes.

public static DateTime ToDateTimeFromUnixTimestampOrDefault(this byte[] array, ref int position, DateTime defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue DateTime

Default value for that type, can be overridden.

Returns

DateTime

Converted DateTime value.

ToDateTimeOffset(byte[], int)

Converts the byte array into a DateTimeOffset. Size = 16 bytes (8 for DateTime, 8 for TimeSpan offset).

public static DateTimeOffset ToDateTimeOffset(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

DateTimeOffset

Converted DateTimeOffset value.

ToDateTimeOffset(byte[], ref int)

Converts the byte array into a DateTimeOffset. Size = 16 bytes (8 for DateTime, 8 for TimeSpan offset).

public static DateTimeOffset ToDateTimeOffset(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

DateTimeOffset

Converted DateTimeOffset value.

ToDateTimeOffsetOrDefault(byte[], int, DateTimeOffset)

Converts the byte array into a DateTimeOffset. Returns the default value if conversion fails. Size = 16 bytes (8 for DateTime, 8 for TimeSpan offset).

public static DateTimeOffset ToDateTimeOffsetOrDefault(this byte[] array, int position = 0, DateTimeOffset defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue DateTimeOffset

Default value for that type, can be overridden.

Returns

DateTimeOffset

Converted DateTimeOffset value.

ToDateTimeOffsetOrDefault(byte[], ref int, DateTimeOffset)

Converts the byte array into a DateTimeOffset. Returns the default value if conversion fails. Size = 16 bytes (8 for DateTime, 8 for TimeSpan offset).

public static DateTimeOffset ToDateTimeOffsetOrDefault(this byte[] array, ref int position, DateTimeOffset defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue DateTimeOffset

Default value for that type, can be overridden.

Returns

DateTimeOffset

Converted DateTimeOffset value.

ToDateTimeOrDefault(byte[], int, DateTime)

Converts the byte array into a DateTime using binary representation. Returns the default value if conversion fails. Size = 8 bytes.

public static DateTime ToDateTimeOrDefault(this byte[] array, int position = 0, DateTime defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue DateTime

Default value for that type, can be overridden.

Returns

DateTime

Converted DateTime value.

ToDateTimeOrDefault(byte[], ref int, DateTime)

Converts the byte array into a DateTime using binary representation. Returns the default value if conversion fails. Size = 8 bytes.

public static DateTime ToDateTimeOrDefault(this byte[] array, ref int position, DateTime defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue DateTime

Default value for that type, can be overridden.

Returns

DateTime

Converted DateTime value.

ToDebugString(IEnumerable<byte>?)

Converts the byte array into a readable string for debugging purposes. Each byte is represented as a decimal value, separated by commas. Returns "<null>" if the input is null.

public static string ToDebugString(this IEnumerable<byte>? array)

Parameters

array IEnumerable<byte>

The byte-enumerable to process.

Returns

string

A string representing the byte-enumerable as comma-separated decimal numbers.

ToDouble(byte[], int)

Converts the byte array into a Signed 64-bit double-precision floating-point number From -1.79769313486232E+308 to 1.79769313486232E+308. Size = 8 bytes.

public static double ToDouble(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

double

Converted value.

ToDouble(byte[], ref int)

Converts the byte array into a Signed 64-bit double-precision floating-point number From -1.79769313486232E+308 to 1.79769313486232E+308. Size = 8 bytes.

public static double ToDouble(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

double

Converted value.

ToDoubleOrDefault(byte[], int, double)

Converts the byte array into a Signed 64-bit double-precision floating-point number From -1.79769313486232E+308 to 1.79769313486232E+308. Size = 8 bytes.

public static double ToDoubleOrDefault(this byte[] array, int position = 0, double defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue double

Default value for that type, can be overriden.

Returns

double

Converted value.

ToDoubleOrDefault(byte[], ref int, double)

Converts the byte array into a Signed 64-bit double-precision floating-point number From -1.79769313486232E+308 to 1.79769313486232E+308. Size = 8 bytes.

public static double ToDoubleOrDefault(this byte[] array, ref int position, double defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue double

Default value for that type, can be overriden.

Returns

double

Converted value.

ToEnumOrDefault<T>(byte[], int, T?)

Converts the byte array into a given Enum.

public static T ToEnumOrDefault<T>(this byte[] array, int position = 0, T? defaultValue = default) where T : Enum

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue T

Default value for that type, can be overriden.

Returns

T

Converted value.

Type Parameters

T

Type of Enum.

ToEnumOrDefault<T>(byte[], ref int, T?)

Converts the byte array into a given Enum.

public static T ToEnumOrDefault<T>(this byte[] array, ref int position, T? defaultValue = default) where T : Enum

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue T

Default value for that type, can be overriden.

Returns

T

Converted value.

Type Parameters

T

Type of Enum.

ToEnum<T>(byte[], int)

Converts the byte array into a given Enum.

public static T ToEnum<T>(this byte[] array, int position = 0) where T : Enum

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

T

Converted value.

Type Parameters

T

Type of Enum.

ToEnum<T>(byte[], ref int)

Converts the byte array into a given Enum.

public static T ToEnum<T>(this byte[] array, ref int position) where T : Enum

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

T

Converted value.

Type Parameters

T

Type of Enum.

Exceptions

ArgumentNullException

Thrown if the array is null.

ToGuid(byte[], int)

Converts the byte array into a GUID. Size = 16 bytes.

public static Guid ToGuid(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

Guid

Converted GUID value.

ToGuid(byte[], ref int)

Converts the byte array into a GUID. Size = 16 bytes.

public static Guid ToGuid(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

Guid

Converted GUID value.

ToGuidOrDefault(byte[], int, Guid)

Converts the byte array into a GUID. Returns the default value if conversion fails. Size = 16 bytes.

public static Guid ToGuidOrDefault(this byte[] array, int position = 0, Guid defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue Guid

Default value for that type, can be overridden.

Returns

Guid

Converted GUID value.

ToGuidOrDefault(byte[], ref int, Guid)

Converts the byte array into a GUID. Returns the default value if conversion fails. Size = 16 bytes.

public static Guid ToGuidOrDefault(this byte[] array, ref int position, Guid defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue Guid

Default value for that type, can be overridden.

Returns

Guid

Converted GUID value.

ToHalf(byte[], int)

Converts the byte array into a 16-bit half-precision floating-point number From approximately -65504 to 65504. Size = 2 bytes.

public static Half ToHalf(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

Half

Converted value.

ToHalf(byte[], ref int)

Converts the byte array into a 16-bit half-precision floating-point number From approximately -65504 to 65504. Size = 2 bytes.

public static Half ToHalf(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

Half

Converted value.

ToHalfOrDefault(byte[], int, Half)

Converts the byte array into a 16-bit half-precision floating-point number From approximately -65504 to 65504. Size = 2 bytes.

public static Half ToHalfOrDefault(this byte[] array, int position = 0, Half defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue Half

Default value for that type, can be overriden.

Returns

Half

Converted value.

ToHalfOrDefault(byte[], ref int, Half)

Converts the byte array into a 16-bit half-precision floating-point number From approximately -65504 to 65504. Size = 2 bytes.

public static Half ToHalfOrDefault(this byte[] array, ref int position, Half defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue Half

Default value for that type, can be overriden.

Returns

Half

Converted value.

ToHexDebugString(IEnumerable<byte>?)

Converts the given byte-array to its hexadecimal string representation for debugging. Each byte is represented as a two-digit hex value, separated by commas. Returns "<null>" if the input is null.

public static string ToHexDebugString(this IEnumerable<byte>? array)

Parameters

array IEnumerable<byte>

The byte-enumerable to process.

Returns

string

A string representing the byte-enumerable as comma-separated hex numbers.

ToHexString(byte[], string, string, bool)

Converts a byte array to a hex string with customizable formatting.

public static string ToHexString(this byte[] array, string separator = "", string prefix = "", bool upperCase = true)

Parameters

array byte[]

The byte array to convert.

separator string

The separator between hex values. Default is empty string.

prefix string

The prefix for each hex value. Default is empty string.

upperCase bool

Whether to use uppercase hex digits. Default is true.

Returns

string

A hex string representation of the byte array.

ToIPAddress(byte[], int, bool)

Converts the byte array into an IPAddress. Size = 4 bytes for IPv4, 16 bytes for IPv6.

public static IPAddress ToIPAddress(this byte[] array, int position = 0, bool isIPv6 = false)

Parameters

array byte[]

The byte array.

position int

The position within the array.

isIPv6 bool

True for IPv6 (16 bytes), false for IPv4 (4 bytes).

Returns

IPAddress

Converted IPAddress value.

ToIPAddress(byte[], ref int, bool)

Converts the byte array into an IPAddress. Size = 4 bytes for IPv4, 16 bytes for IPv6.

public static IPAddress ToIPAddress(this byte[] array, ref int position, bool isIPv6 = false)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

isIPv6 bool

True for IPv6 (16 bytes), false for IPv4 (4 bytes).

Returns

IPAddress

Converted IPAddress value.

ToIPAddressOrDefault(byte[], int, bool, IPAddress?)

Converts the byte array into an IPAddress. Returns the default value if conversion fails. Size = 4 bytes for IPv4, 16 bytes for IPv6.

public static IPAddress ToIPAddressOrDefault(this byte[] array, int position = 0, bool isIPv6 = false, IPAddress? defaultValue = null)

Parameters

array byte[]

The byte array.

position int

The position within the array.

isIPv6 bool

True for IPv6 (16 bytes), false for IPv4 (4 bytes).

defaultValue IPAddress

Default value for that type, can be overridden.

Returns

IPAddress

Converted IPAddress value.

ToIPAddressOrDefault(byte[], ref int, bool, IPAddress?)

Converts the byte array into an IPAddress. Returns the default value if conversion fails. Size = 4 bytes for IPv4, 16 bytes for IPv6.

public static IPAddress ToIPAddressOrDefault(this byte[] array, ref int position, bool isIPv6 = false, IPAddress? defaultValue = null)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

isIPv6 bool

True for IPv6 (16 bytes), false for IPv4 (4 bytes).

defaultValue IPAddress

Default value for that type, can be overridden.

Returns

IPAddress

Converted IPAddress value.

ToIPEndPoint(byte[], int, bool)

Converts the byte array into an IPEndPoint. Size = 6 bytes for IPv4 (4 bytes IP + 2 bytes port), 18 bytes for IPv6 (16 bytes IP + 2 bytes port).

public static IPEndPoint ToIPEndPoint(this byte[] array, int position = 0, bool isIPv6 = false)

Parameters

array byte[]

The byte array.

position int

The position within the array.

isIPv6 bool

True for IPv6, false for IPv4.

Returns

IPEndPoint

Converted IPEndPoint value.

ToIPEndPoint(byte[], ref int, bool)

Converts the byte array into an IPEndPoint. Size = 6 bytes for IPv4 (4 bytes IP + 2 bytes port), 18 bytes for IPv6 (16 bytes IP + 2 bytes port).

public static IPEndPoint ToIPEndPoint(this byte[] array, ref int position, bool isIPv6 = false)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

isIPv6 bool

True for IPv6, false for IPv4.

Returns

IPEndPoint

Converted IPEndPoint value.

ToIPEndPointOrDefault(byte[], int, bool, IPEndPoint?)

Converts the byte array into an IPEndPoint. Returns the default value if conversion fails. Size = 6 bytes for IPv4 (4 bytes IP + 2 bytes port), 18 bytes for IPv6 (16 bytes IP + 2 bytes port).

public static IPEndPoint ToIPEndPointOrDefault(this byte[] array, int position = 0, bool isIPv6 = false, IPEndPoint? defaultValue = null)

Parameters

array byte[]

The byte array.

position int

The position within the array.

isIPv6 bool

True for IPv6, false for IPv4.

defaultValue IPEndPoint

Default value for that type, can be overridden.

Returns

IPEndPoint

Converted IPEndPoint value.

ToIPEndPointOrDefault(byte[], ref int, bool, IPEndPoint?)

Converts the byte array into an IPEndPoint. Returns the default value if conversion fails. Size = 6 bytes for IPv4 (4 bytes IP + 2 bytes port), 18 bytes for IPv6 (16 bytes IP + 2 bytes port).

public static IPEndPoint ToIPEndPointOrDefault(this byte[] array, ref int position, bool isIPv6 = false, IPEndPoint? defaultValue = null)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

isIPv6 bool

True for IPv6, false for IPv4.

defaultValue IPEndPoint

Default value for that type, can be overridden.

Returns

IPEndPoint

Converted IPEndPoint value.

ToInt16(byte[], int)

Converts the byte array into a Signed 16-bit integer From -32,768 to 32,767. Size = 2 bytes.

public static short ToInt16(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

short

Converted value.

ToInt16(byte[], ref int)

Converts the byte array into a Signed 16-bit integer From -32,768 to 32,767. Size = 2 bytes.

public static short ToInt16(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

short

Converted value.

ToInt16BigEndian(byte[], int)

Converts the byte array into a 16-bit integer in big-endian format. Size = 2 bytes.

public static short ToInt16BigEndian(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

short

Converted value.

ToInt16BigEndian(byte[], ref int)

Converts the byte array into a 16-bit integer in big-endian format. Size = 2 bytes.

public static short ToInt16BigEndian(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

short

Converted value.

ToInt16OrDefault(byte[], int, short)

Converts the byte array into a Signed 16-bit integer From -32,768 to 32,767. Size = 2 bytes.

public static short ToInt16OrDefault(this byte[] array, int position = 0, short defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue short

Default value for that type, can be overriden.

Returns

short

Converted value.

ToInt16OrDefault(byte[], ref int, short)

Converts the byte array into a Signed 16-bit integer From -32,768 to 32,767. Size = 2 bytes.

public static short ToInt16OrDefault(this byte[] array, ref int position, short defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue short

Value returned if out of bounds

Returns

short

Converted value.

ToInt32(byte[], int)

Converts the byte array into a Signed 32-bit integer From -2,147,483,648 to 2,147,483,647. Size = 4 bytes.

public static int ToInt32(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

int

Converted value.

ToInt32(byte[], ref int)

Converts the byte array into a Signed 32-bit integer From -2,147,483,648 to 2,147,483,647. Size = 4 bytes.

public static int ToInt32(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

int

Converted value.

ToInt32BigEndian(byte[], int)

Converts the byte array into a 32-bit integer in big-endian format. Size = 4 bytes.

public static int ToInt32BigEndian(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

int

Converted value.

ToInt32BigEndian(byte[], ref int)

Converts the byte array into a 32-bit integer in big-endian format. Size = 4 bytes.

public static int ToInt32BigEndian(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

int

Converted value.

ToInt32OrDefault(byte[], int, int)

Converts the byte array into a Signed 32-bit integer From -2,147,483,648 to 2,147,483,647. Size = 4 bytes.

public static int ToInt32OrDefault(this byte[] array, int position = 0, int defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue int

Default value for that type, can be overriden.

Returns

int

Converted value.

ToInt32OrDefault(byte[], ref int, int)

Converts the byte array into a Signed 32-bit integer From -2,147,483,648 to 2,147,483,647. Size = 4 bytes.

public static int ToInt32OrDefault(this byte[] array, ref int position, int defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue int

Default value for that type, can be overriden.

Returns

int

Converted value.

ToInt64(byte[], int)

Converts the byte array into a Signed 64-bit integer From -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Size = 8 bytes.

public static long ToInt64(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

long

Converted value.

ToInt64(byte[], ref int)

Converts the byte array into a Signed 64-bit integer From -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Size = 8 bytes.

public static long ToInt64(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

long

Converted value.

ToInt64BigEndian(byte[], int)

Converts the byte array into a 64-bit integer in big-endian format. Size = 8 bytes.

public static long ToInt64BigEndian(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

long

Converted value.

ToInt64BigEndian(byte[], ref int)

Converts the byte array into a 64-bit integer in big-endian format. Size = 8 bytes.

public static long ToInt64BigEndian(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

long

Converted value.

ToInt64OrDefault(byte[], int, long)

Converts the byte array into a Signed 64-bit integer From -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Size = 8 bytes.

public static long ToInt64OrDefault(this byte[] array, int position = 0, long defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue long

Default value for that type, can be overriden.

Returns

long

Converted value.

ToInt64OrDefault(byte[], ref int, long)

Converts the byte array into a Signed 64-bit integer From -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Size = 8 bytes.

public static long ToInt64OrDefault(this byte[] array, ref int position, long defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue long

Default value for that type, can be overriden.

Returns

long

Converted value.

ToLengthPrefixedString(byte[], int, Encoding)

Converts a length-prefixed string from the byte array. Format: 2-byte length + string data.

public static string ToLengthPrefixedString(this byte[] array, int position, Encoding encoding)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

encoding Encoding

The encoding to use for conversion.

Returns

string

Converted string value.

ToLengthPrefixedString(byte[], ref int, Encoding)

Converts a length-prefixed string from the byte array. Format: 2-byte length + string data.

public static string ToLengthPrefixedString(this byte[] array, ref int position, Encoding encoding)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

encoding Encoding

The encoding to use for conversion.

Returns

string

Converted string value.

ToNullTerminatedString(byte[], int, Encoding)

Converts a null-terminated string from the byte array.

public static string ToNullTerminatedString(this byte[] array, int position, Encoding encoding)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

encoding Encoding

The encoding to use for conversion.

Returns

string

Converted string value.

ToNullTerminatedString(byte[], ref int, Encoding)

Converts a null-terminated string from the byte array.

public static string ToNullTerminatedString(this byte[] array, ref int position, Encoding encoding)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

encoding Encoding

The encoding to use for conversion.

Returns

string

Converted string value.

ToSByte(byte[], int)

Converts the byte array into a Signed 8-bit integer From -128 to 127. Size = 1 byte.

public static sbyte ToSByte(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

sbyte

Converted value.

ToSByte(byte[], ref int)

Converts the byte array into a Signed 8-bit integer From -128 to 127. Size = 1 byte.

public static sbyte ToSByte(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

sbyte

Converted value.

ToSByteOrDefault(byte[], int, sbyte)

Converts the byte array into a Signed 8-bit integer From -128 to 127. Size = 1 byte.

public static sbyte ToSByteOrDefault(this byte[] array, int position = 0, sbyte defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue sbyte

Value returned if out of bounds

Returns

sbyte

Converted value.

ToSByteOrDefault(byte[], ref int, sbyte)

Converts the byte array into a Signed 8-bit integer From -128 to 127. Size = 1 byte.

public static sbyte ToSByteOrDefault(this byte[] array, ref int position, sbyte defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue sbyte

Value returned if out of bounds

Returns

sbyte

Converted value.

ToSingle(byte[], int)

Converts the byte array into a Signed 32-bit single-precision floating-point number From approximately -3.4 × 10^38 to 3.4 × 10^38. Size = 4 bytes.

public static float ToSingle(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

float

Converted value.

ToSingle(byte[], ref int)

Converts the byte array into a Signed 32-bit single-precision floating-point number From approximately -3.4 × 10^38 to 3.4 × 10^38. Size = 4 bytes.

public static float ToSingle(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

float

Converted value.

ToSingleOrDefault(byte[], int, float)

Converts the byte array into a Signed 32-bit single-precision floating-point number From approximately -3.4 × 10^38 to 3.4 × 10^38. Size = 4 bytes.

public static float ToSingleOrDefault(this byte[] array, int position = 0, float defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue float

Default value for that type, can be overriden.

Returns

float

Converted value.

ToSingleOrDefault(byte[], ref int, float)

Converts the byte array into a Signed 32-bit single-precision floating-point number From approximately -3.4 × 10^38 to 3.4 × 10^38. Size = 4 bytes.

public static float ToSingleOrDefault(this byte[] array, ref int position, float defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue float

Default value for that type, can be overriden.

Returns

float

Converted value.

ToString(byte[], int, Encoding, int)

Converts parts of a byte array into a String using custom encoding.

public static string ToString(this byte[] array, int position, Encoding encoding, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

encoding Encoding

The encoding to use for conversion.

numberOfBytesToRead int

Number of bytes of the expected string

Returns

string

Converted value.

ToString(byte[], ref int, Encoding, int)

Converts parts of a byte array into a String using custom encoding.

public static string ToString(this byte[] array, ref int position, Encoding encoding, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

encoding Encoding

The encoding to use for conversion.

numberOfBytesToRead int

Number of bytes of the expected string

Returns

string

Converted value.

ToTimeSpan(byte[], int)

Converts the byte array into a TimeSpan using ticks representation. Size = 8 bytes.

public static TimeSpan ToTimeSpan(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

TimeSpan

Converted TimeSpan value.

ToTimeSpan(byte[], ref int)

Converts the byte array into a TimeSpan using ticks representation. Size = 8 bytes.

public static TimeSpan ToTimeSpan(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

TimeSpan

Converted TimeSpan value.

ToTimeSpanOrDefault(byte[], int, TimeSpan)

Converts the byte array into a TimeSpan using ticks representation. Returns the default value if conversion fails. Size = 8 bytes.

public static TimeSpan ToTimeSpanOrDefault(this byte[] array, int position = 0, TimeSpan defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue TimeSpan

Default value for that type, can be overridden.

Returns

TimeSpan

Converted TimeSpan value.

ToTimeSpanOrDefault(byte[], ref int, TimeSpan)

Converts the byte array into a TimeSpan using ticks representation. Returns the default value if conversion fails. Size = 8 bytes.

public static TimeSpan ToTimeSpanOrDefault(this byte[] array, ref int position, TimeSpan defaultValue = default)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue TimeSpan

Default value for that type, can be overridden.

Returns

TimeSpan

Converted TimeSpan value.

ToUInt16(byte[], int)

Converts the byte array into a Unsigned 16-bit integer From 0 to 65,535. Size = 2 bytes.

public static ushort ToUInt16(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

ushort

Converted value.

ToUInt16(byte[], ref int)

Converts the byte array into a Unsigned 16-bit integer From 0 to 65,535. Size = 2 bytes.

public static ushort ToUInt16(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

ushort

Converted value.

ToUInt16BigEndian(byte[], int)

Converts the byte array into a 16-bit unsigned integer in big-endian format. Size = 2 bytes.

public static ushort ToUInt16BigEndian(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

ushort

Converted value.

ToUInt16BigEndian(byte[], ref int)

Converts the byte array into a 16-bit unsigned integer in big-endian format. Size = 2 bytes.

public static ushort ToUInt16BigEndian(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

ushort

Converted value.

ToUInt16OrDefault(byte[], int, ushort)

Converts the byte array into a Unsigned 16-bit integer From 0 to 65,535. Size = 2 bytes.

public static ushort ToUInt16OrDefault(this byte[] array, int position = 0, ushort defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue ushort

Default value for that type, can be overriden.

Returns

ushort

Converted value.

ToUInt16OrDefault(byte[], ref int, ushort)

Converts the byte array into a Unsigned 16-bit integer From 0 to 65,535. Size = 2 bytes.

public static ushort ToUInt16OrDefault(this byte[] array, ref int position, ushort defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue ushort

Default value for that type, can be overriden.

Returns

ushort

Converted value.

ToUInt32(byte[], int)

Converts the byte array into a Unsigned 32-bit integer From 0 to 4,294,967,295. Size = 4 bytes.

public static uint ToUInt32(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

uint

Converted value.

ToUInt32(byte[], ref int)

Converts the byte array into a Unsigned 32-bit integer From 0 to 4,294,967,295. Size = 4 bytes.

public static uint ToUInt32(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

uint

Converted value.

ToUInt32BigEndian(byte[], int)

Converts the byte array into a 32-bit unsigned integer in big-endian format. Size = 4 bytes.

public static uint ToUInt32BigEndian(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

uint

Converted value.

ToUInt32BigEndian(byte[], ref int)

Converts the byte array into a 32-bit unsigned integer in big-endian format. Size = 4 bytes.

public static uint ToUInt32BigEndian(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

uint

Converted value.

ToUInt32OrDefault(byte[], int, uint)

Converts the byte array into a Unsigned 32-bit integer From 0 to 4,294,967,295. Size = 4 bytes.

public static uint ToUInt32OrDefault(this byte[] array, int position = 0, uint defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue uint

Default value for that type, can be overriden.

Returns

uint

Converted value.

ToUInt32OrDefault(byte[], ref int, uint)

Converts the byte array into a Unsigned 32-bit integer From 0 to 4,294,967,295. Size = 4 bytes.

public static uint ToUInt32OrDefault(this byte[] array, ref int position, uint defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue uint

Default value for that type, can be overriden.

Returns

uint

Converted value.

ToUInt64(byte[], int)

Converts the byte array into a Unsigned 64-bit integer From 0 to 18,446,744,073,709,551,615. Size = 8 bytes.

public static ulong ToUInt64(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

ulong

Converted value.

ToUInt64(byte[], ref int)

Converts the byte array into a Unsigned 64-bit integer From 0 to 18,446,744,073,709,551,615. Size = 8 bytes.

public static ulong ToUInt64(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

ulong

Converted value.

ToUInt64BigEndian(byte[], int)

Converts the byte array into a 64-bit unsigned integer in big-endian format. Size = 8 bytes.

public static ulong ToUInt64BigEndian(this byte[] array, int position = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

Returns

ulong

Converted value.

ToUInt64BigEndian(byte[], ref int)

Converts the byte array into a 64-bit unsigned integer in big-endian format. Size = 8 bytes.

public static ulong ToUInt64BigEndian(this byte[] array, ref int position)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

Returns

ulong

Converted value.

ToUInt64OrDefault(byte[], int, ulong)

Converts the byte array into a Unsigned 64-bit integer From 0 to 18,446,744,073,709,551,615. Size = 8 bytes.

public static ulong ToUInt64OrDefault(this byte[] array, int position = 0, ulong defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array.

defaultValue ulong

Default value for that type, can be overriden.

Returns

ulong

Converted value.

ToUInt64OrDefault(byte[], ref int, ulong)

Converts the byte array into a Unsigned 64-bit integer From 0 to 18,446,744,073,709,551,615. Size = 8 bytes.

public static ulong ToUInt64OrDefault(this byte[] array, ref int position, ulong defaultValue = 0)

Parameters

array byte[]

The byte array.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

defaultValue ulong

Default value for that type, can be overriden.

Returns

ulong

Converted value.

ToUtf16String(byte[], int, int)

Converts parts of a byte array into a UTF-16 String.

public static string ToUtf16String(this byte[] array, int position = 0, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of bytes of the expected string

Returns

string

Converted value.

ToUtf16String(byte[], ref int, int)

Converts parts of a byte array into a UTF-16 String.

public static string ToUtf16String(this byte[] array, ref int position, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of bytes of the expected string

Returns

string

Converted value.

ToUtf16StringOrDefault(byte[], int, int, string)

Converts parts of a byte array into a UTF-16 String. Returns the default value if conversion fails.

public static string ToUtf16StringOrDefault(this byte[] array, int position = 0, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of bytes of the expected string

defaultValue string

Default value for that type, can be overridden.

Returns

string

Converted value.

ToUtf16StringOrDefault(byte[], ref int, int, string)

Converts parts of a byte array into a UTF-16 String. Returns the default value if conversion fails.

public static string ToUtf16StringOrDefault(this byte[] array, ref int position, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of bytes of the expected string

defaultValue string

Default value for that type, can be overridden.

Returns

string

Converted value.

ToUtf32String(byte[], int, int)

Converts parts of a byte array into a UTF-32 String.

public static string ToUtf32String(this byte[] array, int position = 0, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of bytes of the expected string

Returns

string

Converted value.

ToUtf32String(byte[], ref int, int)

Converts parts of a byte array into a UTF-32 String.

public static string ToUtf32String(this byte[] array, ref int position, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of bytes of the expected string

Returns

string

Converted value.

ToUtf32StringOrDefault(byte[], int, int, string)

Converts parts of a byte array into a UTF-32 String. Returns the default value if conversion fails.

public static string ToUtf32StringOrDefault(this byte[] array, int position = 0, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of bytes of the expected string

defaultValue string

Default value for that type, can be overridden.

Returns

string

Converted value.

ToUtf32StringOrDefault(byte[], ref int, int, string)

Converts parts of a byte array into a UTF-32 String. Returns the default value if conversion fails.

public static string ToUtf32StringOrDefault(this byte[] array, ref int position, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of bytes of the expected string

defaultValue string

Default value for that type, can be overridden.

Returns

string

Converted value.

ToUtf8String(byte[], int, int)

Converts parts of a byte array into a UTF8 String.

public static string ToUtf8String(this byte[] array, int position = 0, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of characters of the expected string

Returns

string

Converted value.

ToUtf8String(byte[], ref int, int)

Converts parts of a byte array into a UTF8 String.

public static string ToUtf8String(this byte[] array, ref int position, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of characters of the expected string

Returns

string

Converted value.

ToUtf8StringOrDefault(byte[], int, int, string)

Converts parts of a byte array into a UTF8 String.

public static string ToUtf8StringOrDefault(this byte[] array, int position = 0, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array.

position int

The position within the array.

numberOfBytesToRead int

Number of characters of the expected string

defaultValue string

Default value for that type, can be overriden.

Returns

string

Converted value.

ToUtf8StringOrDefault(byte[], ref int, int, string)

Converts parts of a byte array into a UTF8 String.

public static string ToUtf8StringOrDefault(this byte[] array, ref int position, int numberOfBytesToRead = -1, string defaultValue = "")

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of characters of the expected string

defaultValue string

Default value for that type, can be overriden.

Returns

string

Converted value.

ToVersion(byte[], int, int)

Converts the full byte array into a Version.

public static Version ToVersion(this byte[] array, int position = 0, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of characters of the expected string

Returns

Version

Converted value.

ToVersion(byte[], ref int, int)

Converts the full byte array into a Version.

public static Version ToVersion(this byte[] array, ref int position, int numberOfBytesToRead = -1)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of characters of the expected string

Returns

Version

Converted value.

ToVersionOrDefault(byte[], int, int, Version?)

Converts the full byte array into a Version.

public static Version ToVersionOrDefault(this byte[] array, int position = 0, int numberOfBytesToRead = -1, Version? defaultValue = null)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array.

numberOfBytesToRead int

Number of characters of the expected string

defaultValue Version

Default value for that type, can be overriden.

Returns

Version

Converted value.

ToVersionOrDefault(byte[], ref int, int, Version?)

Converts the full byte array into a Version.

public static Version ToVersionOrDefault(this byte[] array, ref int position, int numberOfBytesToRead = -1, Version? defaultValue = null)

Parameters

array byte[]

The byte array. Cannot be null.

position int

The position within the array. Byref : is auto-incremented by the size of the output type.

numberOfBytesToRead int

Number of characters of the expected string

defaultValue Version

Default value for that type, can be overriden.

Returns

Version

Converted value.

TrimEnd(byte[], byte)

Removes trailing bytes with the specified value from the array. This method returns a new trimmed array and does not modify the original. Use TrimEndNonDestructive for clarity or this method for backward compatibility.

public static byte[] TrimEnd(this byte[] array, byte byteValueToTrim = 0)

Parameters

array byte[]

The byte array to trim. Cannot be null.

byteValueToTrim byte

The byte value to trim from the end. Default is 0.

Returns

byte[]

A new array with trailing bytes removed.

TrimEndNonDestructive(byte[], byte)

Creates a new byte array with trailing bytes removed (non-destructive version of TrimEnd).

public static byte[] TrimEndNonDestructive(this byte[] array, byte byteValueToTrim = 0)

Parameters

array byte[]

The byte array to process.

byteValueToTrim byte

The byte value to trim from the end. Default is 0.

Returns

byte[]

A new byte array with trailing bytes removed.

Xor(byte[], byte[])

Performs an XOR operation between two byte arrays.

public static byte[] Xor(this byte[] array1, byte[] array2)

Parameters

array1 byte[]

The first array.

array2 byte[]

The second array.

Returns

byte[]

A new byte array containing the XOR result.

Exceptions

ArgumentException

Thrown when arrays have different lengths.