code: public static long reverseByteOrder(long value, int numOfLowerBytesToInvert) {
      if (numOfLowerBytesToInvert < 1 || numOfLowerBytesToInvert > 8) {
        throw new IllegalArgumentException("Wrong number of bytes [" + numOfLowerBytesToInvert + ']');
      }
  
      long result = 0;
  
      int offsetInResult = (numOfLowerBytesToInvert - 1) * 8;
  
      while (numOfLowerBytesToInvert-- > 0) {
        final long thebyte = value & 0xFF;
        value >>>= 8;
        result |= (thebyte << offsetInResult);
        offsetInResult -= 8;
      }
  
      return result;
    }
docs: Revert order for defined number of bytes in a value.
  
  @param value                   the value which bytes should be reordered
  @param numOfLowerBytesToInvert number of lower bytes to be reverted in
  their order, must be 1..8
  @return new value which has reverted order for defined number of lower
  bytes
  @since 1.1