Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Checking if a number is power of two in Julia – ispow2() Method

  • Last Updated : 01 Apr, 2020

The ispow2() is an inbuilt function in julia which is used to test whether the specified number n is a power of two or not.

Syntax: ispow2(n::Integer)

Parameters:

  • n::Integer: Specified number.

Returns: It returns true if the given number is power of 2 else false.

Example 1:






# Julia program to illustrate 
# the use of ispow2() method
   
# Getting true if the given number
# is power of 2 else false.
println(ispow2(1))
println(ispow2(2))
println(ispow2(4))
println(ispow2(8))

Output:

true
true
true
true

Example 2:




# Julia program to illustrate 
# the use of ispow2() method
   
# Getting true if the given number
# is power of 2 else false.
println(ispow2(3))
println(ispow2(5))
println(ispow2(7))
println(ispow2(9))

Output:

false
false
false
false
My Personal Notes arrow_drop_up
Recommended Articles
Page :