Here you can find the source of roundUp(int val, int shift)
Parameter | Description |
---|---|
val | the integer to round up. |
shift | the power of two to round up to. |
public static int roundUp(int val, int shift)
//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; } }