fm.liveswitch.BitAssistant Class Reference

Static Public Member Functions

static byte castByte (int value)
 Casts an integer to a byte. More...
 
static int castInteger (byte value)
 Casts a long to a byte. More...
 
static long castLong (byte value)
 Casts an integer to a byte. More...
 
static byte leftShift (byte value, int count)
 Performs a bit-wise left shift on a byte value. More...
 
static short leftShiftShort (short value, int count)
 Performs a bit-wise left shift on a short value. More...
 
static int leftShiftInteger (int value, int count)
 Performs a bit-wise left shift on an integer value. More...
 
static long leftShiftLong (long value, int count)
 Performs a bit-wise left shift on a long value. More...
 
static byte rightShift (byte value, int count)
 Performs an unsigned bit-wise right shift on a byte value. More...
 
static short rightShiftShort (short value, int count)
 Performs an unsigned bit-wise right shift on a short value. More...
 
static int rightShiftInteger (int value, int count)
 Performs an unsigned bit-wise right shift on an integer value. More...
 
static long rightShiftLong (long value, int count)
 Performs an unsigned bit-wise right shift on a long value. More...
 
static boolean sequencesAreEqual (byte[] array1, byte[] array2)
 Compares two sequences of bytes for equality. More...
 
static boolean sequencesAreEqual (byte[] array1, int offset1, byte[] array2, int offset2, int length)
 Compares two sequences of bytes for equality. More...
 
static boolean sequencesAreEqualConstantTime (byte[] array1, byte[] array2)
 Compares two sequences of bytes for equality in constant time. More...
 
static boolean sequencesAreEqualConstantTime (byte[] array1, int offset1, byte[] array2, int offset2, int length)
 Compares two sequences of bytes for equality in constant time. More...
 
static byte[] subArray (byte[] array, int offset)
 Creates a subarray from an existing array. More...
 
static byte[] subArray (byte[] array, int offset, int count)
 Creates a subarray from an existing array. More...
 
static void reverse (byte[] array)
 Performs an in-place reversal of a byte array. More...
 
static void copy (byte[] source, int sourceIndex, byte[] destination, int destinationIndex, int length)
 Copies bytes from one array to another. More...
 
static void copyFloats (float[] source, int sourceIndex, float[] destination, int destinationIndex, int length)
 Copies floats from one array to another. More...
 
static void set (byte[] array, int index, int length, int value)
 Sets a value across an array. More...
 
static String getHexString (byte[] array)
 Converts a byte array to a hexadecimal string. More...
 
static String getHexString (byte[] array, int offset, int length)
 Converts a byte array to a hexadecimal string. More...
 
static byte[] getHexBytes (String s)
 Converts a hexadecimal string to a byte array. More...
 
static String getBinaryString (byte[] array)
 Converts a byte array to a binary string. More...
 
static String getBinaryString (byte[] array, int offset, int length)
 Converts a byte array to a binary string. More...
 
static byte[] getBinaryBytes (String s)
 Converts a binary string to a byte array. More...
 
static byte[] convertSingleToBytes (float value, boolean littleEndian)
 Converts a single to a byte array. More...
 
static float convertBytesToSingle (byte[] bytes, int index, boolean littleEndian)
 Converts a byte array into a single. More...
 
static byte[] convertDoubleToBytes (double value, boolean littleEndian)
 Convert a double to a byte array. More...
 
static double convertBytesToDouble (byte[] bytes, int index, boolean littleEndian)
 Converts a byte array into a double. More...
 

Member Function Documentation

◆ castByte()

static byte fm.liveswitch.BitAssistant.castByte ( int  value)
static

Casts an integer to a byte.

Parameters
valueThe value.
Returns

◆ castInteger()

static int fm.liveswitch.BitAssistant.castInteger ( byte  value)
static

Casts a long to a byte.

Parameters
valueThe value.
Returns

◆ castLong()

static long fm.liveswitch.BitAssistant.castLong ( byte  value)
static

Casts an integer to a byte.

Parameters
valueThe value.
Returns

◆ convertBytesToDouble()

static double fm.liveswitch.BitAssistant.convertBytesToDouble ( byte[]  bytes,
int  index,
boolean  littleEndian 
)
static

Converts a byte array into a double.

Parameters
bytesThe byte array.
indexThe index.
littleEndianWhether to use little-endian format.

◆ convertBytesToSingle()

static float fm.liveswitch.BitAssistant.convertBytesToSingle ( byte[]  bytes,
int  index,
boolean  littleEndian 
)
static

Converts a byte array into a single.

Parameters
bytesThe byte array.
indexThe index.
littleEndianWhether to use little-endian format.

◆ convertDoubleToBytes()

static byte [] fm.liveswitch.BitAssistant.convertDoubleToBytes ( double  value,
boolean  littleEndian 
)
static

Convert a double to a byte array.

Parameters
valueThe value.
littleEndianWhether to use little-endian format.

◆ convertSingleToBytes()

static byte [] fm.liveswitch.BitAssistant.convertSingleToBytes ( float  value,
boolean  littleEndian 
)
static

Converts a single to a byte array.

Parameters
valueThe value.
littleEndianWhether to use little-endian format.

◆ copy()

static void fm.liveswitch.BitAssistant.copy ( byte[]  source,
int  sourceIndex,
byte[]  destination,
int  destinationIndex,
int  length 
)
static

Copies bytes from one array to another.

Parameters
sourceThe source bytes.
sourceIndexThe starting index for copying from the source.
destinationThe destination bytes.
destinationIndexThe starting index for copying to the destination.
lengthThe number of bytes to copy.

◆ copyFloats()

static void fm.liveswitch.BitAssistant.copyFloats ( float[]  source,
int  sourceIndex,
float[]  destination,
int  destinationIndex,
int  length 
)
static

Copies floats from one array to another.

Parameters
sourceThe source floats.
sourceIndexThe starting index for copying from the source.
destinationThe destination floats.
destinationIndexThe starting index for copying to the destination.
lengthThe number of floats to copy.

◆ getBinaryBytes()

static byte [] fm.liveswitch.BitAssistant.getBinaryBytes ( String  s)
static

Converts a binary string to a byte array.

Parameters
sThe binary string.
Returns
The byte array.

◆ getBinaryString() [1/2]

static String fm.liveswitch.BitAssistant.getBinaryString ( byte[]  array)
static

Converts a byte array to a binary string.

Parameters
arrayThe byte array.
Returns
The binary string.

◆ getBinaryString() [2/2]

static String fm.liveswitch.BitAssistant.getBinaryString ( byte[]  array,
int  offset,
int  length 
)
static

Converts a byte array to a binary string.

Parameters
arrayThe byte array.
offsetThe offset into the array.
lengthThe number of bytes to convert.
Returns
The binary string.

◆ getHexBytes()

static byte [] fm.liveswitch.BitAssistant.getHexBytes ( String  s)
static

Converts a hexadecimal string to a byte array.

Parameters
sThe hexadecimal string.
Returns
The byte array.

◆ getHexString() [1/2]

static String fm.liveswitch.BitAssistant.getHexString ( byte[]  array)
static

Converts a byte array to a hexadecimal string.

Parameters
arrayThe byte array.
Returns

◆ getHexString() [2/2]

static String fm.liveswitch.BitAssistant.getHexString ( byte[]  array,
int  offset,
int  length 
)
static

Converts a byte array to a hexadecimal string.

Parameters
arrayThe byte array.
Returns

◆ leftShift()

static byte fm.liveswitch.BitAssistant.leftShift ( byte  value,
int  count 
)
static

Performs a bit-wise left shift on a byte value.

Parameters
valueThe value.
countThe number of bits to shift.
Returns

◆ leftShiftInteger()

static int fm.liveswitch.BitAssistant.leftShiftInteger ( int  value,
int  count 
)
static

Performs a bit-wise left shift on an integer value.

Parameters
valueThe value.
countThe number of bits to shift.
Returns

◆ leftShiftLong()

static long fm.liveswitch.BitAssistant.leftShiftLong ( long  value,
int  count 
)
static

Performs a bit-wise left shift on a long value.

Parameters
valueThe value.
countThe number of bits to shift.
Returns

◆ leftShiftShort()

static short fm.liveswitch.BitAssistant.leftShiftShort ( short  value,
int  count 
)
static

Performs a bit-wise left shift on a short value.

Parameters
valueThe value.
countThe number of bits to shift.
Returns

◆ reverse()

static void fm.liveswitch.BitAssistant.reverse ( byte[]  array)
static

Performs an in-place reversal of a byte array.

Parameters
arrayThe array to reverse.

◆ rightShift()

static byte fm.liveswitch.BitAssistant.rightShift ( byte  value,
int  count 
)
static

Performs an unsigned bit-wise right shift on a byte value.

Parameters
valueThe value.
countThe number of bits to shift.
Returns

◆ rightShiftInteger()

static int fm.liveswitch.BitAssistant.rightShiftInteger ( int  value,
int  count 
)
static

Performs an unsigned bit-wise right shift on an integer value.

Parameters
valueThe integer value.
countThe number of bits to shift.
Returns

◆ rightShiftLong()

static long fm.liveswitch.BitAssistant.rightShiftLong ( long  value,
int  count 
)
static

Performs an unsigned bit-wise right shift on a long value.

Parameters
valueThe long value.
countThe number of bits to shift.
Returns

◆ rightShiftShort()

static short fm.liveswitch.BitAssistant.rightShiftShort ( short  value,
int  count 
)
static

Performs an unsigned bit-wise right shift on a short value.

Parameters
valueThe short value.
countThe number of bits to shift.
Returns

◆ sequencesAreEqual() [1/2]

static boolean fm.liveswitch.BitAssistant.sequencesAreEqual ( byte[]  array1,
byte[]  array2 
)
static

Compares two sequences of bytes for equality.

Parameters
array1The first byte array.
array2The second byte array.
Returns
true if the sequences are equals; otherwise, false.

◆ sequencesAreEqual() [2/2]

static boolean fm.liveswitch.BitAssistant.sequencesAreEqual ( byte[]  array1,
int  offset1,
byte[]  array2,
int  offset2,
int  length 
)
static

Compares two sequences of bytes for equality.

Parameters
array1The first byte array.
offset1The first byte array offset.
array2The second byte array.
offset2The second byte array offset.
lengthThe length.
Returns
true if the sequences are equal; otherwise, false.

◆ sequencesAreEqualConstantTime() [1/2]

static boolean fm.liveswitch.BitAssistant.sequencesAreEqualConstantTime ( byte[]  array1,
byte[]  array2 
)
static

Compares two sequences of bytes for equality in constant time.

Parameters
array1The first byte array.
array2The second byte array.
Returns
true if the sequences are equal; otherwise, false.

◆ sequencesAreEqualConstantTime() [2/2]

static boolean fm.liveswitch.BitAssistant.sequencesAreEqualConstantTime ( byte[]  array1,
int  offset1,
byte[]  array2,
int  offset2,
int  length 
)
static

Compares two sequences of bytes for equality in constant time.

Parameters
array1The first byte array.
offset1The first byte array offset.
array2The second byte array.
offset2The second byte array offset.
lengthThe length.
Returns
true if the sequences are equal; otherwise, false.

◆ set()

static void fm.liveswitch.BitAssistant.set ( byte[]  array,
int  index,
int  length,
int  value 
)
static

Sets a value across an array.

Parameters
arrayThe array bytes.
indexThe starting index.
lengthThe number of bytes to set.
valueThe value to set.

◆ subArray() [1/2]

static byte [] fm.liveswitch.BitAssistant.subArray ( byte[]  array,
int  offset 
)
static

Creates a subarray from an existing array.

Parameters
arrayThe source array.
offsetThe offset into the source array.
Returns
The subarray.

◆ subArray() [2/2]

static byte [] fm.liveswitch.BitAssistant.subArray ( byte[]  array,
int  offset,
int  count 
)
static

Creates a subarray from an existing array.

Parameters
arrayThe source array.
offsetThe offset into the source array.
countThe number of bytes to copy into the subarray.
Returns
The subarray.