def hitungNomorBit(angka, nomorBit):
if nomorBit != 0 and nomorBit != 1:
return None
if angka < 0:
return None
if angka == 0:
return 1 if nomorBit == 0 else 0
jumlah = 0
while angka > 0:
bit = angka % 2
if bit == nomorBit:
jumlah += 1
angka //= 2
return jumlah
print(hitungNomorBit(13, 0))
print(hitungNomorBit(13, 1))
print(hitungNomorBit(13, 2))
ZGVmIGhpdHVuZ05vbW9yQml0KGFuZ2thLCBub21vckJpdCk6CiAgICBpZiBub21vckJpdCAhPSAwIGFuZCBub21vckJpdCAhPSAxOgogICAgICAgIHJldHVybiBOb25lCgogICAgaWYgYW5na2EgPCAwOgogICAgICAgIHJldHVybiBOb25lCgogICAgaWYgYW5na2EgPT0gMDoKICAgICAgICByZXR1cm4gMSBpZiBub21vckJpdCA9PSAwIGVsc2UgMAoKICAgIGp1bWxhaCA9IDAKCiAgICB3aGlsZSBhbmdrYSA+IDA6CiAgICAgICAgYml0ID0gYW5na2EgJSAyCgogICAgICAgIGlmIGJpdCA9PSBub21vckJpdDoKICAgICAgICAgICAganVtbGFoICs9IDEKCiAgICAgICAgYW5na2EgLy89IDIKCiAgICByZXR1cm4ganVtbGFoCgoKcHJpbnQoaGl0dW5nTm9tb3JCaXQoMTMsIDApKQpwcmludChoaXR1bmdOb21vckJpdCgxMywgMSkpCnByaW50KGhpdHVuZ05vbW9yQml0KDEzLCAyKSkK