FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Bit-Manipulation/IsPowerofFour.js at master · TheAlgorithms/JavaScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TheAlgorithms
/
JavaScript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5.8k
Star
34.2k
Code
Issues
21
Pull requests
192
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Bit-Manipulation
/
IsPowerofFour.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
17 lines (16 loc) · 693 Bytes
Breadcrumbs
JavaScript
/
Bit-Manipulation
/
IsPowerofFour.js
Copy path
File metadata and controls
17 lines (16 loc) · 693 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
*
@author
: dev-madhurendra
* Checks whether the given number is a power of four or not.
*
* A number is considered a power of four if and only if there is a single '1' bit in its binary representation,
* and that '1' bit is at the first position, followed by an even number of '0' bits.
*
*
@param
{
number
} n - The input number to check.
*
@returns
{
boolean
} True if the number is a power of four, false otherwise.
*
*
@example
* const result = isPowerOfFour(16); // Returns true (16 is 4^2)
* const result2 = isPowerOfFour(5); // Returns false (5 is not a power of four)
*/
const
isPowerOfFour
=
(
n
)
=>
n
>
0
&&
(
n
&
(
n
-
1
)
)
===
0
&&
n
%
3
===
1
export
{
isPowerOfFour
}
Back
|
FazBrowse Home
|
New Git URL