Table of Contents

Class EndianBitConverter

Namespace
NLightning.Common.BitUtils
Assembly
NLightning.Common.dll
public static class EndianBitConverter
Inheritance
EndianBitConverter
Inherited Members

Methods

GetBytesBigEndian(short, bool)

Converts a short to a byte array in big-endian order.

public static byte[] GetBytesBigEndian(short value, bool trimToMinimumLenght = false)

Parameters

value short

The short to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the short.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesBigEndian(int, bool)

Converts a int to a byte array in big-endian order.

public static byte[] GetBytesBigEndian(int value, bool trimToMinimumLenght = false)

Parameters

value int

The int to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the int.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesBigEndian(long, bool)

Converts a long to a byte array in big-endian order.

public static byte[] GetBytesBigEndian(long value, bool trimToMinimumLenght = false)

Parameters

value long

The long to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the long.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesBigEndian(ushort, bool)

Converts a ushort to a byte array in big-endian order.

public static byte[] GetBytesBigEndian(ushort value, bool trimToMinimumLenght = false)

Parameters

value ushort

The ushort to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the ushort.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesBigEndian(uint, bool)

Converts a uint to a byte array in big-endian order.

public static byte[] GetBytesBigEndian(uint value, bool trimToMinimumLenght = false)

Parameters

value uint

The uint to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the uint.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesBigEndian(ulong, bool)

Converts a ulong to a byte array in big-endian order.

public static byte[] GetBytesBigEndian(ulong value, bool trimToMinimumLenght = false)

Parameters

value ulong

The ulong to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the ulong.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesLittleEndian(ushort, bool)

Converts a ushort to a byte array in little-endian order.

public static byte[] GetBytesLittleEndian(ushort value, bool trimToMinimumLenght = false)

Parameters

value ushort

The ushort to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the ushort.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesLittleEndian(uint, bool)

Converts a uint to a byte array in little-endian order.

public static byte[] GetBytesLittleEndian(uint value, bool trimToMinimumLenght = false)

Parameters

value uint

The uint to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the uint.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

GetBytesLittleEndian(ulong, bool)

Converts a ulong to a byte array in little-endian order.

public static byte[] GetBytesLittleEndian(ulong value, bool trimToMinimumLenght = false)

Parameters

value ulong

The ulong to convert.

trimToMinimumLenght bool

If true, the byte array will be trimmed to the minimum length.

Returns

byte[]

The byte array representation of the ulong.

Remarks

Trimming to minimum length is useful when the byte array is used in a context where the length is known.

ToInt16BigEndian(byte[], bool)

Converts a byte array to a ushort in big-endian order.

public static short ToInt16BigEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 2.

Returns

short

The ushort representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 2.

ToInt16LittleEndian(byte[], bool)

Converts a byte array to a ushort in little-endian order.

public static short ToInt16LittleEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 2.

Returns

short

The ushort representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 2.

ToInt32BigEndian(byte[], bool)

Converts a byte array to a uint in big-endian order.

public static int ToInt32BigEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 4.

Returns

int

The uint representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 4.

ToInt32LittleEndian(byte[], bool)

Converts a byte array to a uint in little-endian order.

public static int ToInt32LittleEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 4.

Returns

int

The uint representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 4.

ToInt64BigEndian(byte[], bool)

Converts a byte array to a ulong in big-endian order.

public static long ToInt64BigEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 8.

Returns

long

The ulong representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 8.

ToInt64LittleEndian(byte[], bool)

Converts a byte array to a ulong in little-endian order.

public static long ToInt64LittleEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 8.

Returns

long

The ulong representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 8.

ToUInt16BigEndian(byte[], bool)

Converts a byte array to a ushort in big-endian order.

public static ushort ToUInt16BigEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 2.

Returns

ushort

The ushort representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 2.

ToUInt16LittleEndian(byte[], bool)

Converts a byte array to a ushort in little-endian order.

public static ushort ToUInt16LittleEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 2.

Returns

ushort

The ushort representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 2.

ToUInt32BigEndian(byte[], bool)

Converts a byte array to a uint in big-endian order.

public static uint ToUInt32BigEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 4.

Returns

uint

The uint representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 4.

ToUInt32LittleEndian(byte[], bool)

Converts a byte array to a uint in little-endian order.

public static uint ToUInt32LittleEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 4.

Returns

uint

The uint representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 4.

ToUInt64BigEndian(byte[], bool)

Converts a byte array to a ulong in big-endian order.

public static ulong ToUInt64BigEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 8.

Returns

ulong

The ulong representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 8.

ToUInt64LittleEndian(byte[], bool)

Converts a byte array to a ulong in little-endian order.

public static ulong ToUInt64LittleEndian(byte[] bytes, bool padWithZero = false)

Parameters

bytes byte[]

The byte array to convert.

padWithZero bool

If true, the byte array will be padded with zero if the length is less than 8.

Returns

ulong

The ulong representation of the byte array.

Remarks

Padding with zero is useful when the byte array is used in a context where the length is known to be less than 8.