You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

736 B

ispowerof2

Instructions

Write a program that determines if a given number is a power of 2.

This program must print true if the given number is a power of 2, otherwise it prints false.

  • If there is more than one or no argument the program should print a newline ("\n").

  • When there is only 1 argument, it will always be a positive valid int.

Usage :

student@ubuntu:~/ispowerof2$ go build
student@ubuntu:~/ispowerof2$ ./ispowerof2 2 | cat -e
true$
student@ubuntu:~/ispowerof2$ ./ispowerof2 64 | cat -e
true$
student@ubuntu:~/ispowerof2$ ./ispowerof2 513 | cat -e
false$
student@ubuntu:~/ispowerof2$ ./ispowerof2

student@ubuntu:~/ispowerof2$ ./ispowerof2 64 1024

student@ubuntu:~/ispowerof2$