Here you can find the source of roundToPowerOf2(int value)
public static int roundToPowerOf2(int value)
//package com.java2s; //License from project: LGPL public class Main { public static int roundToPowerOf2(int value) { value--;// w w w .j a va 2s . c o m value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; return value + 1; } public static long roundToPowerOf2(long value) { value--; value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; return value + 1; } }