powerOf2

Summary

Tests if a number is would be the result of any exponentiation 2n where n is an integer and the number 2 (two) is the base.

Usage

public static bool powerOf2(unsigned int x)

Returns

true if the specified value is a power of 2 (two) and false otherwise.

Parameters

x

The value to check.

Description

Tests if a number is would be the result of any exponentiation 2n where n is an integer and the number 2 (two) is the base.

Examples

Basic Usage
1
2
3
4
import System;
 
Console.log(Math.powerOf2(4)); // true
Console.log(Math.powerOf2(5)); // false

Share

HTML | BBCode | Direct Link