fork download
  1. function hitungNomorBit(angka, nomorBiner) {
  2. if (nomorBiner !== 0 || nomorBiner !== 1) {
  3. return null
  4. }
  5.  
  6. let biner = [];
  7. let temp = angka;
  8.  
  9. while (temp > 0) {
  10. biner.push(temp % 2);
  11. temp = Math.floor(temp / 2);
  12. }
  13.  
  14. let jumlah = 0;
  15. for (let i = 0; i < biner.length; i++) {
  16. if (biner[i] === nomorBit) {
  17. jumlah++;
  18. }
  19. }
  20.  
  21. return jumlah;
  22. }
Success #stdin #stdout 0.04s 16172KB
stdin
1
2
10
42
11
stdout
Standard output is empty