mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-03 06:17:04 +02:00
17 lines
345 B
TypeScript
17 lines
345 B
TypeScript
/**
|
|
* Determines if the number is a power of 2
|
|
* @param n The number to check.
|
|
*/
|
|
export function isPowerOfTwo(n: number): boolean {
|
|
if (isNaN(n)) {
|
|
return false;
|
|
}
|
|
|
|
if (n === 0) {
|
|
return false;
|
|
}
|
|
|
|
// Disabling the bitwise rule because it's honestly the most efficient way to check for this.
|
|
return (n & (n - 1)) === 0;
|
|
}
|