def hitungNomorBit(angka, nomorBit):
if nomorBit != 0 and nomorBit != 1:
return None
biner = []
if angka == 0:
biner = [0]
while angka > 0:
sisa = angka % 2
biner.insert(0, sisa)
angka = angka // 2
return biner.count(nomorBit)
# pengujian contoh
print(hitungNomorBit(13, 0))
print(hitungNomorBit(13, 1))
print(hitungNomorBit(13, 2))
ZGVmIGhpdHVuZ05vbW9yQml0KGFuZ2thLCBub21vckJpdCk6CiAgICBpZiBub21vckJpdCAhPSAwIGFuZCBub21vckJpdCAhPSAxOgogICAgICAgIHJldHVybiBOb25lCgogICAgYmluZXIgPSBbXQoKICAgIGlmIGFuZ2thID09IDA6CiAgICAgICAgYmluZXIgPSBbMF0KCiAgICB3aGlsZSBhbmdrYSA+IDA6CiAgICAgICAgc2lzYSA9IGFuZ2thICUgMgogICAgICAgIGJpbmVyLmluc2VydCgwLCBzaXNhKQogICAgICAgIGFuZ2thID0gYW5na2EgLy8gMgoKICAgIHJldHVybiBiaW5lci5jb3VudChub21vckJpdCkKCiMgcGVuZ3VqaWFuIGNvbnRvaApwcmludChoaXR1bmdOb21vckJpdCgxMywgMCkpCnByaW50KGhpdHVuZ05vbW9yQml0KDEzLCAxKSkKcHJpbnQoaGl0dW5nTm9tb3JCaXQoMTMsIDIpKQ==