programming-examples/js/Math/Return values that are powers of two.js

7 lines
195 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function isPower_of_two(num)
{
return num && (num & (num - 1)) === 0;
}
console.log(isPower_of_two(64));
console.log(isPower_of_two(94));