/
NikolayIvkin
/
TheAlgorithms
Обзор
Документация
Войти
/
NikolayIvkin
/
TheAlgorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/com/thealgorithms/maths/PowerOfTwoOrNot.java
21 строка
561 B
Piotr Idzik
Add `PowerOfTwoOrNotTest` (#4279)
04 авг 2023, 15:31
Не верифицирован
04 авг 2023, 15:31
c4a9ef1
Код
Авторство
О чём код?
package com.thealgorithms.maths; /** * A utility to check if a given number is power of two or not. For example 8,16 * etc. */ public final class PowerOfTwoOrNot { private PowerOfTwoOrNot() { } /** * Checks whether given number is power of two or not. * * @param number the number to check * @return {@code true} if given number is power of two, otherwise * {@code false} */ public static boolean checkIfPowerOfTwoOrNot(final int number) { return number != 0 && ((number & (number - 1)) == 0); } }