Class BigEndianConversions


  • public final class BigEndianConversions
    extends java.lang.Object
    This is a utility class containing data type conversions using big-endian byte order.
    See Also:
    LittleEndianConversions
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] I2OSP​(int x)
      Convert an integer to an octet string of length 4 according to IEEE 1363, Section 5.5.3.
      static void I2OSP​(int input, byte[] output, int outOff)
      Convert an integer to an octet string of length 4 according to IEEE 1363, Section 5.5.3.
      static void I2OSP​(int input, byte[] output, int outOff, int length)
      Convert an integer to an octet string of the specified length according to IEEE 1363, Section 5.5.3.
      static byte[] I2OSP​(int x, int oLen)
      Convert an integer to an octet string according to IEEE 1363, Section 5.5.3.
      static byte[] I2OSP​(long input)
      Convert an integer to an octet string of length 8 according to IEEE 1363, Section 5.5.3.
      static void I2OSP​(long input, byte[] output, int outOff)
      Convert an integer to an octet string of length 8 according to IEEE 1363, Section 5.5.3.
      static int OS2IP​(byte[] input)
      Convert an octet string to an integer according to IEEE 1363, Section 5.5.3.
      static int OS2IP​(byte[] input, int inOff)
      Convert a byte array of length 4 beginning at offset into an integer.
      static int OS2IP​(byte[] input, int inOff, int inLen)
      Convert an octet string to an integer according to IEEE 1363, Section 5.5.3.
      static long OS2LIP​(byte[] input, int inOff)
      Convert a byte array of length 8 beginning at inOff into a long integer.
      static byte[] toByteArray​(int[] input)
      Convert an int array into a byte array.
      static byte[] toByteArray​(int[] input, int length)
      Convert an int array into a byte array of the specified length.
      static int[] toIntArray​(byte[] input)
      Convert a byte array into an int array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • I2OSP

        public static byte[] I2OSP​(int x)
        Convert an integer to an octet string of length 4 according to IEEE 1363, Section 5.5.3.
        Parameters:
        x - the integer to convert
        Returns:
        the converted integer
      • I2OSP

        public static byte[] I2OSP​(int x,
                                   int oLen)
                            throws java.lang.ArithmeticException
        Convert an integer to an octet string according to IEEE 1363, Section 5.5.3. Length checking is performed.
        Parameters:
        x - the integer to convert
        oLen - the desired length of the octet string
        Returns:
        an octet string of length oLen representing the integer x, or null if the integer is negative
        Throws:
        java.lang.ArithmeticException - if x can't be encoded into oLen octets.
      • I2OSP

        public static void I2OSP​(int input,
                                 byte[] output,
                                 int outOff)
        Convert an integer to an octet string of length 4 according to IEEE 1363, Section 5.5.3.
        Parameters:
        input - the integer to convert
        output - byte array holding the output
        outOff - offset in output array where the result is stored
      • I2OSP

        public static byte[] I2OSP​(long input)
        Convert an integer to an octet string of length 8 according to IEEE 1363, Section 5.5.3.
        Parameters:
        input - the integer to convert
        Returns:
        the converted integer
      • I2OSP

        public static void I2OSP​(long input,
                                 byte[] output,
                                 int outOff)
        Convert an integer to an octet string of length 8 according to IEEE 1363, Section 5.5.3.
        Parameters:
        input - the integer to convert
        output - byte array holding the output
        outOff - offset in output array where the result is stored
      • I2OSP

        public static void I2OSP​(int input,
                                 byte[] output,
                                 int outOff,
                                 int length)
        Convert an integer to an octet string of the specified length according to IEEE 1363, Section 5.5.3. No length checking is performed (i.e., if the integer cannot be encoded into length octets, it is truncated).
        Parameters:
        input - the integer to convert
        output - byte array holding the output
        outOff - offset in output array where the result is stored
        length - the length of the encoding
      • OS2IP

        public static int OS2IP​(byte[] input)
        Convert an octet string to an integer according to IEEE 1363, Section 5.5.3.
        Parameters:
        input - the byte array holding the octet string
        Returns:
        an integer representing the octet string input, or 0 if the represented integer is negative or too large or the byte array is empty
        Throws:
        java.lang.ArithmeticException - if the length of the given octet string is larger than 4.
      • OS2IP

        public static int OS2IP​(byte[] input,
                                int inOff)
        Convert a byte array of length 4 beginning at offset into an integer.
        Parameters:
        input - the byte array
        inOff - the offset into the byte array
        Returns:
        the resulting integer
      • OS2IP

        public static int OS2IP​(byte[] input,
                                int inOff,
                                int inLen)
        Convert an octet string to an integer according to IEEE 1363, Section 5.5.3.
        Parameters:
        input - the byte array holding the octet string
        inOff - the offset in the input byte array where the octet string starts
        inLen - the length of the encoded integer
        Returns:
        an integer representing the octet string bytes, or 0 if the represented integer is negative or too large or the byte array is empty
      • OS2LIP

        public static long OS2LIP​(byte[] input,
                                  int inOff)
        Convert a byte array of length 8 beginning at inOff into a long integer.
        Parameters:
        input - the byte array
        inOff - the offset into the byte array
        Returns:
        the resulting long integer
      • toByteArray

        public static byte[] toByteArray​(int[] input)
        Convert an int array into a byte array.
        Parameters:
        input - the int array
        Returns:
        the converted array
      • toByteArray

        public static byte[] toByteArray​(int[] input,
                                         int length)
        Convert an int array into a byte array of the specified length. No length checking is performed (i.e., if the last integer cannot be encoded into length % 4 octets, it is truncated).
        Parameters:
        input - the int array
        length - the length of the converted array
        Returns:
        the converted array
      • toIntArray

        public static int[] toIntArray​(byte[] input)
        Convert a byte array into an int array.
        Parameters:
        input - the byte array
        Returns:
        the converted array