Pythonは超初心者だけど、こんな感じかな?

str1 = format(15, 'b')
str2 = format(9, 'b')
count = 0
i = 0
while i < len(str1):
if str1[i] == str2[i]:
count += 1
i += 1
print count