Class NumberUtils


  • public class NumberUtils
    extends java.lang.Object
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  NumberUtils.Strategy
      Strategy defining how to manipulate with bytes.
    • Constructor Summary

      Constructors 
      Constructor Description
      NumberUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int readInt​(java.lang.Byte[] word, int strategy)
      Reads an integer from the array of numbers.
      static int readInt​(java.lang.Integer[] word, int strategy)
      Reads an integer from the array of numbers.
      static int reverseBits​(int value, int numberOfBits)
      Reverse bits in integer (max 32-bit) value.
      static java.lang.Byte[] toObjectArray​(byte[] array)  
      static void writeInt​(int value, java.lang.Byte[] output, int strategy)
      Split the value into 4 bytes.
      static void writeInt​(int value, java.lang.Integer[] output, int strategy)
      Split the value into 4 bytes.
      static void writeInt​(int value, java.lang.Short[] output, int strategy)
      Split the value into 4 bytes.
      • Methods inherited from class java.lang.Object

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

      • NumberUtils

        public NumberUtils()
    • Method Detail

      • reverseBits

        public static int reverseBits​(int value,
                                      int numberOfBits)
        Reverse bits in integer (max 32-bit) value.
        Parameters:
        value - value which bits will be reversed
        numberOfBits - how many bits should be reversed. If the value has more bits, the rest will be ignored.
        Returns:
        value with reversed bits
      • toObjectArray

        public static java.lang.Byte[] toObjectArray​(byte[] array)
      • readInt

        public static int readInt​(java.lang.Byte[] word,
                                  int strategy)
        Reads an integer from the array of numbers. Uses binary arithmetic. The array must have 4 items, each one must represent a byte. If the value in the array is larger than a byte, the higher-order bits are cut.
        Parameters:
        word - the array of 4 bytes
        strategy - strategy how to deal with the array. See Strategy class for more information.
        Returns:
        Single integer number which combines the array of bytes into one 32-bit value
      • readInt

        public static int readInt​(java.lang.Integer[] word,
                                  int strategy)
        Reads an integer from the array of numbers. Uses binary arithmetic. The array must have 4 items, each one must represent a byte. If the value in the array is larger than a byte, the higher-order bits are cut.
        Parameters:
        word - the array of 4 bytes
        strategy - strategy how to deal with the array. See Strategy class for more information.
        Returns:
        Single integer number which combines the array of bytes into one 32-bit value
      • writeInt

        public static void writeInt​(int value,
                                    java.lang.Integer[] output,
                                    int strategy)
        Split the value into 4 bytes. Uses binary arithmetic.
        Parameters:
        value - The value which should be split into bytes. It is assumed that it is always in native little endian.
        output - The output array. Must have space for 4 bytes. If the array is larger, other elements are ignored.
        strategy - strategy for how to save the value. See Strategy class for more information.
      • writeInt

        public static void writeInt​(int value,
                                    java.lang.Byte[] output,
                                    int strategy)
        Split the value into 4 bytes. Uses binary arithmetic.
        Parameters:
        value - The value which should be split into bytes. It is assumed that it is always in native little endian.
        output - The output array. Must have space for 4 bytes. If the array is larger, other elements are ignored.
        strategy - strategy for how to save the value. See Strategy class for more information.
      • writeInt

        public static void writeInt​(int value,
                                    java.lang.Short[] output,
                                    int strategy)
        Split the value into 4 bytes. Uses binary arithmetic.
        Parameters:
        value - The value which should be split into bytes. It is assumed that it is always in native little endian.
        output - The output array. Must have space for 4 bytes. If the array is larger, other elements are ignored.
        strategy - strategy for how to save the value. See Strategy class for more information.