Class Bits
Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from the meta data of System.BitConverter. This implementation allows for Endianness consideration.
Inheritance
Namespace: Xrpl.BinaryCodec.Util
Assembly: Xrpl.BinaryCodec.dll
Syntax
public static class Bits : object
Properties
| Improve this Doc View SourceIsLittleEndian
Indicates the byte order ("endianess") in which data is stored in this computer architecture.
Declaration
public static bool IsLittleEndian { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceDoubleToInt64Bits(Double)
Converts the specified double-precision floating point number to a 64-bit signed integer.
Parameters: value: The number to convert.
Returns: A 64-bit signed integer whose value is equivalent to value.
Declaration
public static long DoubleToInt64Bits(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value |
Returns
Type | Description |
---|---|
System.Int64 |
GetBytes(Boolean)
Returns the specified Boolean value as an array of bytes.
Parameters: value: A Boolean value.
Returns: An array of bytes with length 1.
Declaration
public static byte[] GetBytes(bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Byte)
Declaration
public static byte[] GetBytes(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Char)
Returns the specified Unicode character value as an array of bytes.
Parameters: value: A character to convert.
Returns: An array of bytes with length 2.
Declaration
public static byte[] GetBytes(char value)
Parameters
Type | Name | Description |
---|---|---|
System.Char | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Double)
Returns the specified double-precision floating point value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 8.
Declaration
public static byte[] GetBytes(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Int16)
Returns the specified 16-bit signed integer value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 2.
Declaration
public static byte[] GetBytes(short value)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Int32)
Returns the specified 32-bit signed integer value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 4.
Declaration
public static byte[] GetBytes(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Int64)
Returns the specified 64-bit signed integer value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 8.
Declaration
public static byte[] GetBytes(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(Single)
Returns the specified single-precision floating point value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 4.
Declaration
public static byte[] GetBytes(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(UInt16)
Returns the specified 16-bit unsigned integer value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 2.
Declaration
public static byte[] GetBytes(ushort value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(UInt32)
Returns the specified 32-bit unsigned integer value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 4.
Declaration
public static byte[] GetBytes(uint value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | value |
Returns
Type | Description |
---|---|
System.Byte[] |
GetBytes(UInt64)
Returns the specified 64-bit unsigned integer value as an array of bytes.
Parameters: value: The number to convert.
Returns: An array of bytes with length 8.
Declaration
public static byte[] GetBytes(ulong value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | value |
Returns
Type | Description |
---|---|
System.Byte[] |
Int64BitsToDouble(Int64)
Converts the specified 64-bit signed integer to a double-precision floating point number.
Parameters: value: The number to convert.
Returns: A double-precision floating point number whose value is equivalent to value.
Declaration
public static double Int64BitsToDouble(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value |
Returns
Type | Description |
---|---|
System.Double |
ToBoolean(Byte[], Int32)
Returns a Boolean value converted from one byte at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: true if the byte at startIndex in value is nonzero; otherwise, false.
Exceptions: System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static bool ToBoolean(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Boolean |
ToChar(Byte[], Int32)
Returns a Unicode character converted from two bytes at a specified position in a byte array.
Parameters: value: An array.
startIndex: The starting position within value.
Returns: A character formed by two bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex equals the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static char ToChar(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Char |
ToDouble(Byte[], Int32)
Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A double precision floating point number formed by eight bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static double ToDouble(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Double |
ToInt16(Byte[], Int32)
Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A 16-bit signed integer formed by two bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex equals the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static short ToInt16(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Int16 |
ToInt32(Byte[], Int32)
Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A 32-bit signed integer formed by four bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static int ToInt32(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Int32 |
ToInt64(Byte[], Int32)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A 64-bit signed integer formed by eight bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static long ToInt64(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Int64 |
ToSingle(Byte[], Int32)
Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A single-precision floating point number formed by four bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static float ToSingle(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.Single |
ToString(Byte[])
Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.
Parameters: value: An array of bytes.
Returns: A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A".
Exceptions: System.ArgumentNullException: value is null.
Declaration
public static string ToString(byte[] value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value |
Returns
Type | Description |
---|---|
System.String |
ToString(Byte[], Int32)
Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".
Exceptions: System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static string ToString(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.String |
ToString(Byte[], Int32, Int32)
Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
length: The number of array elements in value to convert.
Returns: A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".
Exceptions: System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex or length is less than zero. -or- startIndex is greater than zero and is greater than or equal to the length of value.
System.ArgumentException: The combination of startIndex and length does not specify a position within value; that is, the startIndex parameter is greater than the length of value minus the length parameter.
Declaration
public static string ToString(byte[] value, int startIndex, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex | |
System.Int32 | length |
Returns
Type | Description |
---|---|
System.String |
ToUInt16(Byte[], Int32)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
Parameters: value: The array of bytes.
startIndex: The starting position within value.
Returns: A 16-bit unsigned integer formed by two bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex equals the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static ushort ToUInt16(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.UInt16 |
ToUInt32(Byte[], Int32)
Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A 32-bit unsigned integer formed by four bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static uint ToUInt32(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.UInt32 |
ToUInt64(Byte[], Int32)
Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
Parameters: value: An array of bytes.
startIndex: The starting position within value.
Returns: A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.
Exceptions: System.ArgumentException: startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.
System.ArgumentNullException: value is null.
System.ArgumentOutOfRangeException: startIndex is less than zero or greater than the length of value minus 1.
Declaration
public static ulong ToUInt64(byte[] value, int startIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | |
System.Int32 | startIndex |
Returns
Type | Description |
---|---|
System.UInt64 |