Here you can find the source of roundDown(int val, int shift)
Parameter | Description |
---|---|
val | the integer to round down. |
shift | the power of two to round down to. |
public static int roundDown(int val, int shift)
//package com.java2s; /*/*from ww w . j a v a 2 s . com*/ * 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 down to the nearest multiple of {@code 2^shift}. * Works with both positive and negative integers. * @param val the integer to round down. * @param shift the power of two to round down to. * @return the rounded integer. */ public static int roundDown(int val, int shift) { return val >>> shift << shift; } }