ispow2()
是 julia 中的一个内置函数,用于测试指定的数字n是否是 2 的幂。
Syntax: ispow2(n::Integer)
Parameters:
- n::Integer: Specified number.
Returns: It returns true if the given number is power of 2 else false.
示例 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))
输出:
true
true
true
true
示例 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))
输出:
false
false
false
false