Problem 1226. Non-zero bits in 10^n.
Given an integer that is a power of 10, find the number of non-zero bits, k, in its binary representation.
For example:
- n = 1, 10^n = 1010, so k = 2.
- n = 5, 10^n = 11000011010100000, so k = 6.
The solution should work for arbitrarily large powers n, say at least till n = 100.
Solution Stats
Problem Comments
-
2 Comments
Peter Wittenberg
on 28 Jan 2013
I can't get the last three cases to work out. I've checked the answers a couple of different ways. I still get 26 1s in the binary for 10^100. Is there a defect in the solutions offered?
SK
on 30 Jan 2013
The test cases are correct. In case you are using dec2bin, it is subject to loss of significance.
Solution Comments
Show commentsProblem Recent Solvers40
Suggested Problems
-
Select every other element of a vector
34155 Solvers
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15632 Solvers
-
Find state names that start with the letter N
1323 Solvers
-
given 3 sides, find area of this triangle
807 Solvers
-
Project Euler: Problem 5, Smallest multiple
1507 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!