Class UnsignedConversions


  • public class UnsignedConversions
    extends Object
    Conversion utilities between unsigned primitives and standard Java primitives.

    Since we need all the combinations and since the standard libraries provide only some, we chose to re-implement all the cases here for readability and convenience. Note that the only conversions that are different are the widening from unsigned to signed. All other conversions are the same.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static BigInteger toBigInteger​(long unsignedValue)
      Converts an unsigned long to a BigInteger.
      static double toDouble​(byte unsignedValue)
      Converts an unsigned byte to a double.
      static double toDouble​(int unsignedValue)
      Converts an unsigned int to a double.
      static double toDouble​(long unsignedValue)
      Converts an unsigned long to a double.
      static double toDouble​(short unsignedValue)
      Converts an unsigned short to a double.
      static float toFloat​(byte unsignedValue)
      Converts an unsigned byte to a float.
      static float toFloat​(int unsignedValue)
      Converts an unsigned int to a float.
      static float toFloat​(long unsignedValue)
      Converts an unsigned long to a float.
      static float toFloat​(short unsignedValue)
      Converts an unsigned short to a float.
      static int toInt​(byte unsignedValue)
      Converts an unsigned byte to a int.
      static int toInt​(short unsignedValue)
      Converts an unsigned short to a int.
      static long toLong​(byte unsignedValue)
      Converts an unsigned byte to a long.
      static long toLong​(int unsignedValue)
      Converts an unsigned int to a long.
      static long toLong​(short unsignedValue)
      Converts an unsigned short to a long.
      static short toShort​(byte unsignedValue)
      Converts an unsigned byte to a short.
    • Method Detail

      • toShort

        public static short toShort​(byte unsignedValue)
        Converts an unsigned byte to a short.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toInt

        public static int toInt​(byte unsignedValue)
        Converts an unsigned byte to a int.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toInt

        public static int toInt​(short unsignedValue)
        Converts an unsigned short to a int.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toLong

        public static long toLong​(byte unsignedValue)
        Converts an unsigned byte to a long.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toLong

        public static long toLong​(short unsignedValue)
        Converts an unsigned short to a long.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toLong

        public static long toLong​(int unsignedValue)
        Converts an unsigned int to a long.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toFloat

        public static float toFloat​(byte unsignedValue)
        Converts an unsigned byte to a float.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toFloat

        public static float toFloat​(short unsignedValue)
        Converts an unsigned short to a float.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toFloat

        public static float toFloat​(int unsignedValue)
        Converts an unsigned int to a float.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toFloat

        public static float toFloat​(long unsignedValue)
        Converts an unsigned long to a float.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toDouble

        public static double toDouble​(byte unsignedValue)
        Converts an unsigned byte to a double.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toDouble

        public static double toDouble​(short unsignedValue)
        Converts an unsigned short to a double.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toDouble

        public static double toDouble​(int unsignedValue)
        Converts an unsigned int to a double.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toDouble

        public static double toDouble​(long unsignedValue)
        Converts an unsigned long to a double.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value
      • toBigInteger

        public static BigInteger toBigInteger​(long unsignedValue)
        Converts an unsigned long to a BigInteger.
        Parameters:
        unsignedValue - unsigned value
        Returns:
        the converted value