Problem 56603. Is the number of 1s in a binary integer odd or even?
Your function should turn the input integers into binary form and count the number of 1s in the binary. If the number is odd, return -1; else, return 1 (for each input).
For example, if the input number is 10:
- Turn it into binary form: 1010
- Count 1s in the binary: 2
- Judge if it's even or odd: even
- So the output is 1.
Try to find the best algorithm! My best size is 22.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers22
Suggested Problems
-
Which values occur exactly three times?
5232 Solvers
-
4280 Solvers
-
Return elements unique to either input
803 Solvers
-
344 Solvers
-
Removing rows from a matrix is easy - but what about inserting rows?
261 Solvers
More from this Author14
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!