Java Array Max Value maxbits(int[] i, int pos, int length)

Here you can find the source of maxbits(int[] i, int pos, int length)

Description

get the msb of all the elements between the range of pos and length of the input list

License

Open Source License

Parameter

Parameter Description
i input list
pos start position
length end position

Return

msb of the list

Declaration

public static int maxbits(int[] i, int pos, int length) 

Method Source Code

//package com.java2s;
/**/*from  w w w  .j a va2s .com*/
 * This code is released under the
 * Apache License Version 2.0 http://www.apache.org/licenses/.
 *
 * (c) Daniel Lemire, http://lemire.me/en/
 */

public class Main {
    /**
     * get the msb of all the elements between the range of pos and length of
     * the input list
     * 
     * @param i
     *            input list
     * @param pos
     *            start position
     * @param length
     *            end position
     * @return msb of the list
     */
    public static int maxbits(int[] i, int pos, int length) {
        int mask = 0;
        for (int k = pos; k < pos + length; ++k)
            mask |= i[k];
        return bits(mask);
    }

    public static int bits(int i) {
        return 32 - Integer.numberOfLeadingZeros(i);
    }
}

Related

  1. maxAbs(float[] a, int off, int length)
  2. maxarr(double[] a)
  3. maxArray(double[] input)
  4. maxArray(int[] arr)
  5. maxBetween(int[] arr1, int[] arr2)
  6. maxbits32(int[] i, int pos)
  7. maxCommonLeadingWhitespaceForAll(String[] strings)
  8. maxcount(int[] vals, int max, int maxcount)
  9. maxDblArrayValue(int npts, double[] dbls)