Java Number Round roundUp(int val, int shift)

Here you can find the source of roundUp(int val, int shift)

Description

Rounds an integer up to the nearest multiple of 2^shift .

License

Open Source License

Parameter

Parameter Description
val the integer to round up.
shift the power of two to round up to.

Return

the rounded integer.

Declaration

public static int roundUp(int val, int shift) 

Method Source Code

//package com.java2s;
/*/*  ww  w.  jav  a2  s .  co m*/
 * Copyright (c) 2009.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

public class Main {
    /**
     * Rounds an integer up to the nearest multiple of {@code 2^shift}.
     * Works with both positive and negative integers.
     * @param val the integer to round up.
     * @param shift the power of two to round up to.
     * @return the rounded integer.
     */
    public static int roundUp(int val, int shift) {
        return (val + (1 << shift) - 1) >>> shift << shift;
    }
}

Related

  1. roundUp(int ndigits)
  2. roundUp(int num, int divisor)
  3. roundUp(int number, int interval)
  4. roundUp(int p_154354_0_, int p_154354_1_)
  5. roundUp(int v, int quant)
  6. roundUp(int val, int to)
  7. roundUp(int x, int blockSizePowerOf2)
  8. roundUp(long n, long m)
  9. roundUp(long number, long mod)