function hitungNomorBitManual(angka, nomorBit) {
let hasil = 0;
let angkaDihitung = angka;
if (nomorBit !== 0 && nomorBit !== 1) {
hasil = null;
return null;
}
while (angkaDihitung > 0) {
const bit = angkaDihitung % 2;
if (bit === nomorBit) {
hasil++;
}
angkaDihitung = Math.floor(angkaDihitung / 2);
}
return hasil;
}
ZnVuY3Rpb24gaGl0dW5nTm9tb3JCaXRNYW51YWwoYW5na2EsIG5vbW9yQml0KSB7CiAgbGV0IGhhc2lsID0gMDsKICBsZXQgYW5na2FEaWhpdHVuZyA9IGFuZ2thOwoKICBpZiAobm9tb3JCaXQgIT09IDAgJiYgbm9tb3JCaXQgIT09IDEpIHsKICAgIGhhc2lsID0gbnVsbDsKICAgIHJldHVybiBudWxsOwogIH0KCiAgd2hpbGUgKGFuZ2thRGloaXR1bmcgPiAwKSB7CiAgICBjb25zdCBiaXQgPSBhbmdrYURpaGl0dW5nICUgMjsKCiAgICBpZiAoYml0ID09PSBub21vckJpdCkgewogICAgICBoYXNpbCsrOwogICAgfQoKICAgIGFuZ2thRGloaXR1bmcgPSBNYXRoLmZsb29yKGFuZ2thRGloaXR1bmcgLyAyKTsKICB9CgogIHJldHVybiBoYXNpbDsKfQ==