I want to check whether the number given is a power of 2. I have written a code but I cannot return true or false, I think somewhere there is an infinite loop. I am only allowed to use functions from imported packages on the code. I could not figure out what to do to correct the mistake. I would be glad if you can help me :)
package main
import (
"os"
"strconv"
)
func main() {
for len(os.Args) == 2 {
numbers, err := strconv.Atoi(os.Args[1])
if err != nil {
panic(err)
}
newnum := numbers
counts := 0
for numbers != 1 {
if newnum%2 != 0 {
} else {
newnum = newnum / 2
}
counts++
}
var x int = 2 ^ counts
if x == numbers {
return true
} else {
return false
}
}
}
`