Table of Contents

Class Convertible

Namespace
Cuemon
Assembly
Cuemon.Core.dll

Provides a set of static methods, suitable for verifying integrity of data, that convert IConvertible implementations to and from a sequence of bytes.

public static class Convertible
Inheritance
Convertible

Fields

BitsPerByte

Defines how many bits is needed for one byte.

public const int BitsPerByte = 8

Field Value

Int32

BitsPerNibble

Defines how many bits is needed for one nibble (one hexadecimal digit).

public const int BitsPerNibble = 4

Field Value

Int32

NullValue

A representation for a null value when converting to a byte[].

public const int NullValue = 0

Field Value

Int32

Methods

GetBytes(Boolean, Action<EndianOptions>)

Returns the specified Boolean as a byte[].

public static byte[] GetBytes(bool input, Action<EndianOptions> setup = null)

Parameters

input Boolean

The Boolean to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Byte, Action<EndianOptions>)

Returns the specified Byte as a byte[].

public static byte[] GetBytes(byte input, Action<EndianOptions> setup = null)

Parameters

input Byte

The Byte to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Char, Action<EndianOptions>)

Returns the specified Char as a byte[].

public static byte[] GetBytes(char input, Action<EndianOptions> setup = null)

Parameters

input Char

The Char to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(IEnumerable<IConvertible>, Action<ConvertibleOptions>)

Returns the specified sequence of IConvertible as an aggregated byte[].

public static byte[] GetBytes(IEnumerable<IConvertible> input, Action<ConvertibleOptions> setup = null)

Parameters

input IEnumerable<IConvertible>

The IEnumerable<T> sequence to convert.

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Byte[]

An aggregated byte[] that is otherwise equivalent to input.

GetBytes(DateTime)

Returns the specified DateTime as a byte[].

public static byte[] GetBytes(DateTime input)

Parameters

input DateTime

The DateTime to convert.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(DBNull)

Returns the specified DBNull as a byte[].

public static byte[] GetBytes(DBNull input)

Parameters

input DBNull

The DBNull to convert.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Decimal)

Returns the specified Decimal as a byte[].

public static byte[] GetBytes(decimal input)

Parameters

input Decimal

The Decimal to convert.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Double, Action<EndianOptions>)

Returns the specified Double as a byte[].

public static byte[] GetBytes(double input, Action<EndianOptions> setup = null)

Parameters

input Double

The Double to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Enum, Action<EndianOptions>)

Returns the specified Enum as a byte[].

public static byte[] GetBytes(Enum input, Action<EndianOptions> setup = null)

Parameters

input Enum

The Enum to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(IConvertible, Action<ConvertibleOptions>)

Returns the specified IConvertible as a byte[].

public static byte[] GetBytes(IConvertible input, Action<ConvertibleOptions> setup = null)

Parameters

input IConvertible

The IConvertible implementation to convert.

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

Exceptions

ArgumentOutOfRangeException

input is an unknown implementation of IConvertible; please use RegisterConvertible to make a custom implementation globally known -or- use setup to add a custom implementation using ConvertibleOptions.Converters..Add.

GetBytes(Int16, Action<EndianOptions>)

Returns the specified Int16 as a byte[].

public static byte[] GetBytes(short input, Action<EndianOptions> setup = null)

Parameters

input Int16

The Int16 to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Int32, Action<EndianOptions>)

Returns the specified Int32 as a byte[].

public static byte[] GetBytes(int input, Action<EndianOptions> setup = null)

Parameters

input Int32

The Int32 to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Int64, Action<EndianOptions>)

Returns the specified Int64 as a byte[].

public static byte[] GetBytes(long input, Action<EndianOptions> setup = null)

Parameters

input Int64

The Int64 to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(SByte, Action<EndianOptions>)

Returns the specified SByte as a byte[].

public static byte[] GetBytes(sbyte input, Action<EndianOptions> setup = null)

Parameters

input SByte

The SByte to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(Single, Action<EndianOptions>)

Returns the specified Single as a byte[].

public static byte[] GetBytes(float input, Action<EndianOptions> setup = null)

Parameters

input Single

The Single to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(String, Action<EncodingOptions>)

Returns the specified String as its equivalent byte[] representation.

public static byte[] GetBytes(string input, Action<EncodingOptions> setup = null)

Parameters

input String

The String to convert.

setup Action<EncodingOptions>

The EncodingOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

Remarks

Exceptions

ArgumentNullException

input cannot be null.

InvalidEnumArgumentException

setup was initialized with an invalid Preamble.

GetBytes(UInt16, Action<EndianOptions>)

Returns the specified UInt16 as a byte[].

public static byte[] GetBytes(ushort input, Action<EndianOptions> setup = null)

Parameters

input UInt16

The UInt16 to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(UInt32, Action<EndianOptions>)

Returns the specified UInt32 as a byte[].

public static byte[] GetBytes(uint input, Action<EndianOptions> setup = null)

Parameters

input UInt32

The UInt32 to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

GetBytes(UInt64, Action<EndianOptions>)

Returns the specified UInt64 as a byte[].

public static byte[] GetBytes(ulong input, Action<EndianOptions> setup = null)

Parameters

input UInt64

The UInt64 to convert.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that is equivalent to input.

RegisterConvertible<T>(Func<T, Byte[]>)

Registers the specified IConvertible implementation of T to make it globally known.

public static void RegisterConvertible<T>(Func<T, byte[]> converter)
    where T : IConvertible

Parameters

converter Func<T, Byte[]>

The function delegate that converts an IConvertible implementation to its equivalent byte[].

Type Parameters

T

The type of the IConvertible implementation to use.

Exceptions

ArgumentNullException

converter cannot be null.

ReverseBits16(UInt16)

Reverse the bits of the specified input.

public static ushort ReverseBits16(ushort input)

Parameters

input UInt16

The unsigned 16-bit integer to reverse bits on.

Returns

UInt16

A UInt16 with the bits reversed.

ReverseBits32(UInt32)

Reverse the bits of the specified input.

public static uint ReverseBits32(uint input)

Parameters

input UInt32

The unsigned 32-bit integer to reverse bits on.

Returns

UInt32

A UInt32 with the bits reversed.

ReverseBits64(UInt64)

Reverse the bits of the specified input.

public static ulong ReverseBits64(ulong input)

Parameters

input UInt64

The unsigned 64-bit integer to reverse bits on.

Returns

UInt64

A UInt64 with the bits reversed.

ReverseBits8(Byte)

Reverse the bits of the specified input.

public static byte ReverseBits8(byte input)

Parameters

input Byte

The unsigned 8-bit integer to reverse bits on.

Returns

Byte

A Byte with the bits reversed.

ReverseEndianness(Byte[], Action<EndianOptions>)

Reverse the endianness of the specified input.

public static byte[] ReverseEndianness(byte[] input, Action<EndianOptions> setup = null)

Parameters

input Byte[]

The byte[] to reverse.

setup Action<EndianOptions>

The EndianOptions which may be configured.

Returns

Byte[]

A byte[] that, depending on the setup, is either equal or a reversed value of input.

ToString(Byte[], Action<EncodingOptions>)

Returns the specified byte[] as its equivalent String representation.

public static string ToString(byte[] input, Action<EncodingOptions> setup = null)

Parameters

input Byte[]

The byte[] to convert.

setup Action<EncodingOptions>

The EncodingOptions which may be configured.

Returns

String

A String that is equivalent to input.

Remarks

Exceptions

ArgumentNullException

input cannot be null.

InvalidEnumArgumentException

setup was initialized with an invalid Preamble.