Determines if value is powered by two. - Java java.lang

Java examples for java.lang:Math Calculation

Description

Determines if value is powered by two.

Demo Code


//package com.java2s;

public class Main {
    /**//  www. j  a  va2s .c o m
     * Determines if value is powered by two.
     * 
     * @param value
     *        A value.
     * @return {@code true} if {@code value} is powered by two; otherwise {@code false}.
     */
    public static boolean isPowerOfTwo(int value) {
        return (value > 0) && ((value & (value - 1)) == 0);
    }
}

Related Tutorials