Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static int getNextHigherPowerOfTwo(int num) { if (num <= 0) return 1; int highestBit = Integer.highestOneBit(num); return num <= highestBit ? highestBit : highestBit << 1; } }