|
|
|
## 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`.
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
- If there is more than one or no argument the program should print nothing.
|
|
|
|
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
- When there is only one argument, it will always be a positive valid int.
|
|
|
|
|
|
|
|
### Usage :
|
|
|
|
|
|
|
|
```console
|
|
|
|
student@ubuntu:~/ispowerof2$ go build
|
|
|
|
student@ubuntu:~/ispowerof2$ ./ispowerof2 2 | cat -e
|
|
|
|
true$
|
Refactor & Beautify & destruction commit
return early, remove else branches, reorder conditions and top-level functions, remove empty lines, remove unnecessary append(), fix typos, stop using testing package, remove dead code, fix mistakes in subjects, tests and solutions, remove disclaimers, reformat comments, simplify solutions, tests, add more instructions to subjects, remove obsolete files, etc.
Some of the reasons behind those modifications will be added to good-practices.en.md
Some of the exercises are now broken, they will have to be fixed, most of them have a "TODO:" comment.
5 years ago
|
|
|
student@ubuntu:~/ispowerof2$ ./ispowerof2 64
|
|
|
|
true
|
|
|
|
student@ubuntu:~/ispowerof2$ ./ispowerof2 513
|
|
|
|
false
|
|
|
|
student@ubuntu:~/ispowerof2$ ./ispowerof2
|
|
|
|
student@ubuntu:~/ispowerof2$ ./ispowerof2 64 1024
|
|
|
|
student@ubuntu:~/ispowerof2$
|
|
|
|
```
|