Module vcr4j.rs422

Class NumberUtilities

java.lang.Object
org.mbari.vcr4j.rs422.util.NumberUtilities

public class NumberUtilities extends Object

Useful static methods for manipulating numbers.

  • Method Summary

    Modifier and Type
    Method
    Description
    static final byte[]
    toByteArray(char c)
    Converts an char to the corresponding byte[] array.
    static final byte[]
    toByteArray(char c, boolean isReverseOrder)
    Description of the Method
    static 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[] array
    static 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[] array
    static 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[] array
    static 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[] array
    static 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[] array
    static final char
    toChar(byte[] si)
    Convert a byte[] (most significant byte first) to the corresponding char value.
    static final char
    toChar(byte[] si, boolean isReverseOrder)
    Convert a byte[] to the corresponding char value.
    static final double
    toDouble(byte[] si)
    Convert a byte[] (most significant byte first) to the corresponding double value.
    static final double
    toDouble(byte[] si, boolean isReverseOrder)
    Convert a byte[] to the corresponding double value.
    static final float
    toFloat(byte[] si)
    Convert a byte[] (most significant byte first) to the corresponding float value.
    static final float
    toFloat(byte[] si, boolean isReverseOrder)
    Convert a byte[] to the corresponding float value.
    static String
    toHexString(byte[] b)
    Format a byte array as a hexadecimal string.
    static final int
    toInt(byte[] si)
    Convert a byte[] (most significant byte first) to the corresponding int value.
    static final int
    toInt(byte[] si, boolean isReverseOrder)
    Convert a byte[] to the corresponding int value.
    static final long
    toLong(byte[] si)
    Convert a byte[] (most significant byte first) to the corresponding long value.
    static final long
    toLong(byte[] si, boolean isReverseOrder)
    Convert a byte[] to the corresponding long value.
    static final short
    toShort(byte[] si)
    Convert a byte[] (most significant byte first) to the corresponding short value.
    static final short
    toShort(byte[] si, boolean isReverseOrder)
    Convert a byte[] to the corresponding short value.
    static int
    Convert an unsigned byte to an integer

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 Parameter
      isReverseOrder - 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 input
      isReverseOrder - 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 input
      isReverseOrder - 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 input
      isReverseOrder - 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 array
      isReverseOrder - 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 array
      isReverseOrder - 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 array
      isReverseOrder - 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 array
      isReverseOrder - 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 array
      isReverseOrder - 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 array
      isReverseOrder - 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

      public static String toHexString(byte[] b)
      Format a byte array as a hexadecimal string. For example
       byte[] bytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0};
       String hex = NumberUtilities.toHexString(bytes); // 120ff0