Class BitAssistant
Contains methods for cross-platform bit manipulation.
Inheritance
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public class BitAssistant : object
Methods
CastByte(Int32)
Casts an integer to a byte.
Declaration
public static byte CastByte(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value. |
Returns
Type | Description |
---|---|
System.Byte |
CastInteger(Byte)
Casts a byte to an integer.
Declaration
public static int CastInteger(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The value. |
Returns
Type | Description |
---|---|
System.Int32 |
CastLong(Byte)
Casts a byte to a long.
Declaration
public static long CastLong(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The value. |
Returns
Type | Description |
---|---|
System.Int64 |
ConvertBytesToDouble(Byte[], Int32, Boolean)
Converts a byte array into a double.
Declaration
public static double ConvertBytesToDouble(byte[] bytes, int index, bool littleEndian)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | The byte array. |
System.Int32 | index | The index. |
System.Boolean | littleEndian | Whether to use little-endian format. |
Returns
Type | Description |
---|---|
System.Double |
ConvertBytesToSingle(Byte[], Int32, Boolean)
Converts a byte array into a single.
Declaration
public static float ConvertBytesToSingle(byte[] bytes, int index, bool littleEndian)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | The byte array. |
System.Int32 | index | The index. |
System.Boolean | littleEndian | Whether to use little-endian format. |
Returns
Type | Description |
---|---|
System.Single |
ConvertDoubleToBytes(Double, Boolean)
Convert a double to a byte array.
Declaration
public static byte[] ConvertDoubleToBytes(double value, bool littleEndian)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The value. |
System.Boolean | littleEndian | Whether to use little-endian format. |
Returns
Type | Description |
---|---|
System.Byte[] |
ConvertSingleToBytes(Single, Boolean)
Converts a single to a byte array.
Declaration
public static byte[] ConvertSingleToBytes(float value, bool littleEndian)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value. |
System.Boolean | littleEndian | Whether to use little-endian format. |
Returns
Type | Description |
---|---|
System.Byte[] |
Copy(Byte[], Int32, Byte[], Int32, Int32)
Copies bytes from one array to another.
Declaration
public static void Copy(byte[] source, int sourceIndex, byte[] destination, int destinationIndex, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | source | The source bytes. |
System.Int32 | sourceIndex | The starting index for copying from the source. |
System.Byte[] | destination | The destination bytes. |
System.Int32 | destinationIndex | The starting index for copying to the destination. |
System.Int32 | length | The number of bytes to copy. |
GetBinaryBytes(String)
Converts a binary string to a byte array.
Declaration
public static byte[] GetBinaryBytes(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The binary string. |
Returns
Type | Description |
---|---|
System.Byte[] | The byte array. |
GetBinaryString(Byte[])
Converts a byte array to a binary string.
Declaration
public static string GetBinaryString(byte[] array)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The byte array. |
Returns
Type | Description |
---|---|
System.String | The binary string. |
GetBinaryString(Byte[], Int32, Int32)
Converts a byte array to a binary string.
Declaration
public static string GetBinaryString(byte[] array, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The byte array. |
System.Int32 | offset | The offset into the array. |
System.Int32 | length | The number of bytes to convert. |
Returns
Type | Description |
---|---|
System.String | The binary string. |
GetHexBytes(String)
Converts a hexadecimal string to a byte array.
Declaration
public static byte[] GetHexBytes(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The hexadecimal string. |
Returns
Type | Description |
---|---|
System.Byte[] | The byte array. |
GetHexString(Byte[])
Converts a byte array to a hexadecimal string.
Declaration
public static string GetHexString(byte[] array)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The byte array. |
Returns
Type | Description |
---|---|
System.String | The hexadecimal string. |
GetHexString(Byte[], Int32, Int32)
Converts a byte array to a hexadecimal string.
Declaration
public static string GetHexString(byte[] array, int offset, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The byte array. |
System.Int32 | offset | The offset into the array. |
System.Int32 | length | The number of bytes to convert. |
Returns
Type | Description |
---|---|
System.String | The hexadecimal string. |
LeftShift(Byte, Int32)
Performs a bit-wise left shift on a byte value.
Declaration
public static byte LeftShift(byte value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Byte |
LeftShiftInteger(Int32, Int32)
Performs a bit-wise left shift on an integer value.
Declaration
public static int LeftShiftInteger(int value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Int32 |
LeftShiftLong(Int64, Int32)
Performs a bit-wise left shift on a long value.
Declaration
public static long LeftShiftLong(long value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Int64 |
LeftShiftShort(Int16, Int32)
Performs a bit-wise left shift on a short value.
Declaration
public static short LeftShiftShort(short value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | value | The value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Int16 |
Reverse(Byte[])
Performs an in-place reversal of a byte array.
Declaration
public static void Reverse(byte[] array)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The array to reverse. |
RightShift(Byte, Int32)
Performs an unsigned bit-wise right shift on a byte value.
Declaration
public static byte RightShift(byte value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Byte |
RightShiftInteger(Int32, Int32)
Performs an unsigned bit-wise right shift on an integer value.
Declaration
public static int RightShiftInteger(int value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The integer value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Int32 |
RightShiftLong(Int64, Int32)
Performs an unsigned bit-wise right shift on a long value.
Declaration
public static long RightShiftLong(long value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The long value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Int64 |
RightShiftShort(Int16, Int32)
Performs an unsigned bit-wise right shift on a short value.
Declaration
public static short RightShiftShort(short value, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | value | The short value. |
System.Int32 | count | The number of bits to shift. |
Returns
Type | Description |
---|---|
System.Int16 |
SequencesAreEqual(Byte[], Byte[])
Compares two sequences of bytes for equality.
Declaration
public static bool SequencesAreEqual(byte[] array1, byte[] array2)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array1 | The first byte array. |
System.Byte[] | array2 | The second byte array. |
Returns
Type | Description |
---|---|
System.Boolean |
|
SequencesAreEqual(Byte[], Int32, Byte[], Int32, Int32)
Compares two sequences of bytes for equality.
Declaration
public static bool SequencesAreEqual(byte[] array1, int offset1, byte[] array2, int offset2, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array1 | The first byte array. |
System.Int32 | offset1 | The first byte array offset. |
System.Byte[] | array2 | The second byte array. |
System.Int32 | offset2 | The second byte array offset. |
System.Int32 | length | The length. |
Returns
Type | Description |
---|---|
System.Boolean |
|
SequencesAreEqualConstantTime(Byte[], Byte[])
Compares two sequences of bytes for equality in constant time.
Declaration
public static bool SequencesAreEqualConstantTime(byte[] array1, byte[] array2)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array1 | The first byte array. |
System.Byte[] | array2 | The second byte array. |
Returns
Type | Description |
---|---|
System.Boolean |
|
SequencesAreEqualConstantTime(Byte[], Int32, Byte[], Int32, Int32)
Compares two sequences of bytes for equality in constant time.
Declaration
public static bool SequencesAreEqualConstantTime(byte[] array1, int offset1, byte[] array2, int offset2, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array1 | The first byte array. |
System.Int32 | offset1 | The first byte array offset. |
System.Byte[] | array2 | The second byte array. |
System.Int32 | offset2 | The second byte array offset. |
System.Int32 | length | The length. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Set(Byte[], Int32, Int32, Byte)
Sets a value across an array.
Declaration
public static void Set(byte[] array, int index, int length, byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The array bytes. |
System.Int32 | index | The starting index. |
System.Int32 | length | The number of bytes to set. |
System.Byte | value | The value to set. |
SubArray(Byte[], Int32)
Creates a subarray from an existing array.
Declaration
public static byte[] SubArray(byte[] array, int offset)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The source array. |
System.Int32 | offset | The offset into the source array. |
Returns
Type | Description |
---|---|
System.Byte[] | The subarray. |
SubArray(Byte[], Int32, Int32)
Creates a subarray from an existing array.
Declaration
public static byte[] SubArray(byte[] array, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | The source array. |
System.Int32 | offset | The offset into the source array. |
System.Int32 | count | The number of bytes to copy into the subarray. |
Returns
Type | Description |
---|---|
System.Byte[] | The subarray. |