Class FlexibleBitConverter
- Namespace
- PushTechnology.ClientInterface
- Assembly
- Diffusion.Client.dll
The collection of methods for converting an array of bytes to one of the base data types, as well as for converting a base data type to an array of bytes.
public static class FlexibleBitConverter
- Inheritance
-
FlexibleBitConverter
- Inherited Members
Remarks
All methods are able to distinguish between little-endian and big-endian byte ordering.
Properties
SystemByteOrder
Returns the byte order of the current architecture.
public static ByteOrder SystemByteOrder { get; }
Property Value
- ByteOrder
The byte order of the current architecture.
Methods
GetBytes(char, ByteOrder)
Returns the specified 16-bit character value as an array of bytes.
public static byte[] GetBytes(char value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 2.
GetBytes(char, byte[], int, ByteOrder)
Writes the specified 16-bit character value into the given byte array.
public static void GetBytes(char value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valuecharThe value to convert.
resultbyte[]The byte array to write the character to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(double, ByteOrder)
Returns the specified 64-bit floating point value as an array of bytes.
public static byte[] GetBytes(double value, ByteOrder resultByteOrder)
Parameters
valuedoubleThe value to convert.
resultByteOrderByteOrderThe byte order for the resulting array.
Returns
- byte[]
An array of bytes with length 8.
GetBytes(double, byte[], int, ByteOrder)
Writes the specified 64-bit floating point value into the given byte array.
public static void GetBytes(double value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valuedoubleThe value to convert.
resultbyte[]The byte array to write the floating point to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(short, ByteOrder)
Returns the specified 16-bit signed integer value as an array of bytes.
public static byte[] GetBytes(short value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 2.
GetBytes(short, byte[], int, ByteOrder)
Writes the specified 16-bit signed integer value into the given byte array.
public static void GetBytes(short value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valueshortThe value to convert.
resultbyte[]The byte array to write the integer to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(int, ByteOrder)
Returns the specified 32-bit signed integer value as an array of bytes.
public static byte[] GetBytes(int value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 4.
GetBytes(int, byte[], int, ByteOrder)
Writes the specified 32-bit signed integer value into the given byte array.
public static void GetBytes(int value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valueintThe value to convert.
resultbyte[]The byte array to write the integer to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(long, ByteOrder)
Returns the specified 64-bit signed integer value as an array of bytes.
public static byte[] GetBytes(long value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 8.
GetBytes(long, byte[], int, ByteOrder)
Writes the specified 64-bit signed integer value into the given byte array.
public static void GetBytes(long value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valuelongThe value to convert.
resultbyte[]The byte array to write the integer to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(float, ByteOrder)
Returns the specified 32-bit floating point value as an array of bytes.
public static byte[] GetBytes(float value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 4.
GetBytes(float, byte[], int, ByteOrder)
Writes the specified 32-bit floating point value into the given byte array.
public static void GetBytes(float value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valuefloatThe value to convert.
resultbyte[]The byte array to write the floating point to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(ushort, ByteOrder)
Returns the specified 16-bit unsigned integer value as an array of bytes.
public static byte[] GetBytes(ushort value, ByteOrder resultByteOrder)
Parameters
valueushortThe value to convert.
resultByteOrderByteOrderThe byte order for the resulting array.
Returns
- byte[]
An array of bytes with length 2.
GetBytes(ushort, byte[], int, ByteOrder)
Writes the specified 16-bit unsigned integer value into the given byte array.
public static void GetBytes(ushort value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valueushortThe value to convert.
resultbyte[]The byte array to write the integer to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(uint, ByteOrder)
Returns the specified 32-bit unsigned integer value as an array of bytes.
public static byte[] GetBytes(uint value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 4.
GetBytes(uint, byte[], int, ByteOrder)
Writes the specified 32-bit unsigned integer value into the given byte array.
public static void GetBytes(uint value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valueuintThe value to convert.
resultbyte[]The byte array to write the integer to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
GetBytes(ulong, ByteOrder)
Returns the specified 64-bit unsigned integer value as an array of bytes.
public static byte[] GetBytes(ulong value, ByteOrder resultByteOrder)
Parameters
Returns
- byte[]
An array of bytes with length 8.
GetBytes(ulong, byte[], int, ByteOrder)
Writes the specified 64-bit unsigned integer value into the given byte array.
public static void GetBytes(ulong value, byte[] result, int offset, ByteOrder resultByteOrder)
Parameters
valueulongThe value to convert.
resultbyte[]The byte array to write the integer to.
offsetintThe starting index of the result buffer.
resultByteOrderByteOrderThe byte order for the resulting array.
Exceptions
- ArgumentNullException
The given result array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given result array.
ToChar(byte[], int, ByteOrder)
Returns a 16-bit character converted from two bytes at a specified position in a byte array.
public static char ToChar(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the character from.
offsetintThe starting index of the character within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- char
A 16-bit character formed by two bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToDouble(byte[], int, ByteOrder)
Returns a 64-bit floating point converted from eight bytes at a specified position in a byte array.
public static double ToDouble(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the floating point from.
offsetintThe starting index of the floating point within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- double
A 64-bit floating point formed by eight bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToHalf(byte[], int, ByteOrder)
Returns a 16-bit floating point converted from eight bytes at a specified position in a byte array.
public static float ToHalf(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the floating point from.
offsetintThe starting index of the floating point within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- float
A 16-bit floating point formed by eight bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToInt16(byte[], int, ByteOrder)
Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
public static short ToInt16(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the integer from.
offsetintThe starting index of the integer within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- short
A 16-bit signed integer formed by two bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToInt32(byte[], int, ByteOrder)
Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
public static int ToInt32(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the integer from.
offsetintThe starting index of the integer within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- int
A 32-bit signed integer formed by four bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToInt64(byte[], int, ByteOrder)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
public static long ToInt64(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the integer from.
offsetintThe starting index of the integer within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- long
A 64-bit signed integer formed by eight bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToSingle(byte[], int, ByteOrder)
Returns a 32-bit floating point converted from eight bytes at a specified position in a byte array.
public static float ToSingle(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the floating point from.
offsetintThe starting index of the floating point within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- float
A 32-bit floating point formed by eight bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToUInt16(byte[], int, ByteOrder)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
public static ushort ToUInt16(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the integer from.
offsetintThe starting index of the integer within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- ushort
A 16-bit unsigned integer formed by two bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToUInt32(byte[], int, ByteOrder)
Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
public static uint ToUInt32(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the integer from.
offsetintThe starting index of the integer within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- uint
A 32-bit unsigned integer formed by four bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.
ToUInt64(byte[], int, ByteOrder)
Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
public static ulong ToUInt64(byte[] value, int offset, ByteOrder valueByteOrder)
Parameters
valuebyte[]The byte array to read the integer from.
offsetintThe starting index of the integer within the byte array.
valueByteOrderByteOrderThe byte order of the given byte array.
Returns
- ulong
A 64-bit signed integer formed by eight bytes beginning at
offset.
Exceptions
- ArgumentNullException
The given array is
null.- ArgumentOutOfRangeException
The given offset is negative or bigger than the given array.