FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExercises/Experiments/IsPowerOfTwo.java at master · biblelamp/JavaExercises · GitHub
biblelamp
/
JavaExercises
Public
Notifications
You must be signed in to change notification settings
Fork
130
Star
153
Code
Issues
1
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExercises
/
Experiments
/
IsPowerOfTwo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
15 lines (13 loc) · 424 Bytes
Breadcrumbs
JavaExercises
/
Experiments
/
IsPowerOfTwo.java
Copy path
File metadata and controls
15 lines (13 loc) · 424 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
/*
* How to know if a number is a power of two
*/
class
IsPowerOfTwo
{
public
static
void
main
(
String
[]
args
) {
long
[]
a
= {
4
,
1024
,
2048
,
0xd9af54e703bb08deL
};
for
(
long
x
:
a
) {
long
y
= (
x
& (
x
-
1
));
// y must equal to 0 if x is a power of two
// OR (x & (~x + 1)) - y must equal to x
System
.
out
.
println
(
x
+
":"
+
y
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL