```
class Solution(object):
def countBits(self, num):
"""
:type num: int
:rtype: List[int]
"""
def sum_digits(n):
s = 0
while n:
s += n % 10
n //= 10
return s
res =[]
for i in xrange(0,num+1):
b = int('{0:08b}'.format(i))
res.append(sum_digits(b))
return res
```