Java Number Min Value minPower2(int n)

Here you can find the source of minPower2(int n)

Description

Find the minimal power of 2 that is larger than n.

License

Open Source License

Return

the minimal power of 2 that larger than n.

Declaration

public static int minPower2(int n) 

Method Source Code

//package com.java2s;
/**/*w  w w . ja  v  a  2 s. c o m*/
 * Utilities to link BIJ things to ImageJ.
 *
 * Copyright (c) 1999-2004, Michael Abramoff. All rights reserved.
 * @author: Michael Abramoff
 *
 * Small print:
 * This source code, and any derived programs ('the software')
 * are the intellectual property of Michael Abramoff.
 * Michael Abramoff asserts his right as the sole owner of the rights
 * to this software.
 * Commercial licensing of the software is available by contacting the author.
 * THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 */

public class Main {
    /**
     * Find the minimal power of 2 that is larger than n.
     * @return the minimal power of 2 that larger than n.
     */
    public static int minPower2(int n) {
        int newn = 2;
        while (newn < n)
            newn *= 2;
        return newn;
    }
}

Related

  1. minOfThree(final long a, final long b, final long c)
  2. minP(int a, long b)
  3. minPos(int a, int b)
  4. minPos(int a, int b)
  5. minPositive(int a, int b)
  6. minRunLength(int n)
  7. minShareLifetime(long shareLifetime1, long shareLifetime2)
  8. minSignedIntForBitSize(final int bitSize)
  9. minSignedIntForBitSize_noCheck(final int bitSize)