java.lang.Object
org.mbari.vcr4j.rs422.util.NumberUtilities
Useful static methods for manipulating numbers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic final byte[]toByteArray(char c) Converts an char to the corresponding byte[] array.static final byte[]toByteArray(char c, boolean isReverseOrder) Description of the Methodstatic final byte[]toByteArray(double d) Converts a double to the corresponding byte[] array.static final byte[]toByteArray(double d, boolean isReverseOrder) Converts a double to the corresponding byte[] arraystatic final byte[]toByteArray(float f) Converts a float to the corresponding byte[] array.static final byte[]toByteArray(float f, boolean isReverseOrder) Converts a float to the corresponding byte[] arraystatic final byte[]toByteArray(int i) Converts an integer to the corresponding byte[] array.static final byte[]toByteArray(int i, boolean isReverseOrder) Converts an integer to the corresponding byte[] arraystatic final byte[]toByteArray(long l) Converts a long to the corresponding byte[] array.static final byte[]toByteArray(long l, boolean isReverseOrder) Converts a long to the corresponding byte[] arraystatic final byte[]toByteArray(short i) Converts a short to the corresponding byte[] array.static final byte[]toByteArray(short i, boolean isReverseOrder) Converts a short to the corresponding byte[] arraystatic final chartoChar(byte[] si) Convert a byte[] (most significant byte first) to the corresponding char value.static final chartoChar(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding char value.static final doubletoDouble(byte[] si) Convert a byte[] (most significant byte first) to the corresponding double value.static final doubletoDouble(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding double value.static final floattoFloat(byte[] si) Convert a byte[] (most significant byte first) to the corresponding float value.static final floattoFloat(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding float value.static StringtoHexString(byte[] b) Format a byte array as a hexadecimal string.static final inttoInt(byte[] si) Convert a byte[] (most significant byte first) to the corresponding int value.static final inttoInt(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding int value.static final longtoLong(byte[] si) Convert a byte[] (most significant byte first) to the corresponding long value.static final longtoLong(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding long value.static final shorttoShort(byte[] si) Convert a byte[] (most significant byte first) to the corresponding short value.static final shorttoShort(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding short value.static intunsignedBytetoInt(byte b) Convert an unsigned byte to an integer
-
Method Details
-
toByteArray
public static final byte[] toByteArray(char c) Converts an char to the corresponding byte[] array. Most significant byte is first.- Parameters:
c- char input- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(double d) Converts a double to the corresponding byte[] array. Most significant byte is first.- Parameters:
d- Integer input- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(float f) Converts a float to the corresponding byte[] array. Most significant byte is first.- Parameters:
f- float input- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(int i) Converts an integer to the corresponding byte[] array. Most significant byte is first.- Parameters:
i- Integer input- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(long l) Converts a long to the corresponding byte[] array. Most significant byte is first.- Parameters:
l- long input- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(short i) Converts a short to the corresponding byte[] array. Most significant byte is first.- Parameters:
i- Integer input- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(char c, boolean isReverseOrder) Description of the Method- Parameters:
c- Description of the ParameterisReverseOrder- Description of the Parameter- Returns:
- Description of the Return Value
-
toByteArray
public static final byte[] toByteArray(double d, boolean isReverseOrder) Converts a double to the corresponding byte[] array- Parameters:
isReverseOrder- True if the ordering is least significant byte to most signifigant byte, false for most significant to least.d- Description of the Parameter- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(float f, boolean isReverseOrder) Converts a float to the corresponding byte[] array- Parameters:
f- Short inputisReverseOrder- True if the ordering is least significant byte to most signifigant byte, false for most significant to least.- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(int i, boolean isReverseOrder) Converts an integer to the corresponding byte[] array- Parameters:
i- Integer inputisReverseOrder- True if the ordering is least significant byte to most signifigant byte, false for most significant to least.- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(long l, boolean isReverseOrder) Converts a long to the corresponding byte[] array- Parameters:
isReverseOrder- True if the ordering is least significant byte to most signifigant byte, false for most significant to least.l- Description of the Parameter- Returns:
- Byte array corresponding to the input
-
toByteArray
public static final byte[] toByteArray(short i, boolean isReverseOrder) Converts a short to the corresponding byte[] array- Parameters:
i- Short inputisReverseOrder- True if the ordering is least significant byte to most signifigant byte, false for most significant to least.- Returns:
- Byte array corresponding to the input
-
toChar
public static final char toChar(byte[] si) Convert a byte[] (most significant byte first) to the corresponding char value.- Parameters:
si- the input array- Returns:
- The value coresponding to the byte array
-
toChar
public static final char toChar(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding char value.- Parameters:
si- the input arrayisReverseOrder- True if llittle-endian. False if big-endian (Most significant byte first)- Returns:
- The value coresponding to the byte array
-
toDouble
public static final double toDouble(byte[] si) Convert a byte[] (most significant byte first) to the corresponding double value.- Parameters:
si- the input array- Returns:
- The value coresponding to the byte array
-
toDouble
public static final double toDouble(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding double value.- Parameters:
si- the input arrayisReverseOrder- True if llittle-endian. False if big-endian (Most significant byte first)- Returns:
- The value coresponding to the byte array
-
toFloat
public static final float toFloat(byte[] si) Convert a byte[] (most significant byte first) to the corresponding float value.- Parameters:
si- the input array- Returns:
- The value coresponding to the byte array
-
toFloat
public static final float toFloat(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding float value.- Parameters:
si- the input arrayisReverseOrder- True if llittle-endian. False if big-endian (Most significant byte first)- Returns:
- The value coresponding to the byte array
-
toInt
public static final int toInt(byte[] si) Convert a byte[] (most significant byte first) to the corresponding int value.- Parameters:
si- the input array- Returns:
- The value coresponding to the byte array
-
toInt
public static final int toInt(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding int value.- Parameters:
si- the input arrayisReverseOrder- True if little-endian. False if big-endian (Most significant byte first)- Returns:
- The value coresponding to the byte array
-
toLong
public static final long toLong(byte[] si) Convert a byte[] (most significant byte first) to the corresponding long value.- Parameters:
si- the input array- Returns:
- The value coresponding to the byte array
-
toLong
public static final long toLong(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding long value.- Parameters:
si- the input arrayisReverseOrder- True if llittle-endian. False if big-endian (Most significant byte first)- Returns:
- The value coresponding to the byte array
-
toShort
public static final short toShort(byte[] si) Convert a byte[] (most significant byte first) to the corresponding short value.- Parameters:
si- the input array- Returns:
- The value coresponding to the byte array
-
toShort
public static final short toShort(byte[] si, boolean isReverseOrder) Convert a byte[] to the corresponding short value.- Parameters:
si- the input arrayisReverseOrder- True if llittle-endian. False if big-endian (Most significant byte first)- Returns:
- The value coresponding to the byte array
-
unsignedBytetoInt
public static int unsignedBytetoInt(byte b) Convert an unsigned byte to an integer- Parameters:
b- byte to convert- Returns:
- integer corresponding to the unsigned byte.
-
toHexString
Format a byte array as a hexadecimal string. For examplebyte[] bytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0}; String hex = NumberUtilities.toHexString(bytes); // 120ff0
-