IsPowerOfTwo | R Documentation |
This function checks to see whether its input is a power of two. If it is then it returns that power otherwise it returns NA.
IsPowerOfTwo(n)
n |
Vector of numbers that are to be checked whether it is a power of two. |
Function takes the log of the input, divides this by log(2) and if the result is integral then it knows the input is true power of two.
If n
is a power of two, then the power is returned otherwise NA
is returned.
Version 3.6.0 Copyright Guy Nason 1995
G P Nason
nlevelsWT.default
.
# # Try and see whether 1,2,3 or 4 are powers of two! # IsPowerOfTwo(1:4) # [1] 0 1 NA 2 # # Yes, 1,2 and 4 are the 0, 1 and 2nd power of 2. However, 3 is not an # integral power of two.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.