Table of Contents

Class BitConverterEx

Namespace
Utils.Objects
Assembly
Utils.dll

Provides methods for converting between decimal, Int128, UInt128 and their corresponding byte representations. This class supplements BitConverter with conversions not natively supported.

public static class BitConverterEx
Inheritance
BitConverterEx
Inherited Members

Methods

GetBytes(decimal)

Converts the specified decimal value into its 16-byte binary representation.

public static byte[] GetBytes(decimal d)

Parameters

d decimal

The decimal value to convert.

Returns

byte[]

A 16-byte array representing the specified decimal.

GetBytes(Int128)

Converts an Int128 value into its 16-byte binary representation.

public static byte[] GetBytes(Int128 i)

Parameters

i Int128

The Int128 value to convert.

Returns

byte[]

A 16-byte array representing the Int128 value.

GetBytes(UInt128)

Converts a UInt128 value into its 16-byte binary representation.

public static byte[] GetBytes(UInt128 i)

Parameters

i UInt128

The UInt128 value to convert.

Returns

byte[]

A 16-byte array representing the UInt128 value.

ToDecimal(ReadOnlySpan<byte>)

Converts a 16-byte ReadOnlySpan<T> of bytes into a decimal.

public static decimal ToDecimal(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

A read-only span of at least 16 bytes that contains the binary representation of a decimal value.

Returns

decimal

A decimal instance whose binary representation is taken from the first 16 bytes of bytes.

Exceptions

ArgumentException

Thrown if bytes does not contain exactly 16 bytes.

ToInt128(ReadOnlySpan<byte>)

Converts a 16-byte ReadOnlySpan<T> of bytes into an Int128.

public static Int128 ToInt128(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

A read-only span of exactly 16 bytes that contains the binary representation of an Int128 value.

Returns

Int128

An Int128 parsed from the specified span.

Exceptions

ArgumentException

Thrown if bytes does not contain exactly 16 bytes.

ToUInt128(ReadOnlySpan<byte>)

Converts a 16-byte ReadOnlySpan<T> of bytes into a UInt128.

public static UInt128 ToUInt128(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

A read-only span of exactly 16 bytes that contains the binary representation of a UInt128 value.

Returns

UInt128

A UInt128 parsed from the specified span.

Exceptions

ArgumentException

Thrown if bytes does not contain exactly 16 bytes.