fork download
  1. function hitungNomorBitManual(angka, nomorBit) {
  2. let count = 0;
  3. let tempNumber = angka;
  4.  
  5. if (nomorBit !== 0 && nomorBit !== 1) {
  6. count = null;
  7. return null;
  8. }
  9.  
  10. while (tempNumber > 0) {
  11. const currentBit = tempNumber % 2;
  12.  
  13. if (currentBit === nomorBit) {
  14. count++;
  15. }
  16.  
  17. tempNumber = Math.floor(tempNumber / 2);
  18. }
  19.  
  20. return count;
  21. }
Success #stdin #stdout 0.02s 16860KB
stdin
Standard input is empty
stdout
Standard output is empty