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