next Power Of Two - Android java.lang

Android examples for java.lang:Math

Description

next Power Of Two

Demo Code

/*/*  w ww  .j  a va2  s .c om*/
 * Copyright (c) 2012-2013 OrangeSignal.com All Rights Reserved.
 */
//package com.java2s;

public class Main {

    public static int nextPowerOfTwo(final int x) {
        return (int) Math.pow(2, Math.ceil(log2(x)));
    }

    public static double log2(final double x) {
        return Math.log(x) / Math.log(2);
    }
}

Related Tutorials