Contact: aviboots(AT)netvision.net.il
40,904 questions
53,356 answers
573 users
function Count1Bit(n: number) { let count = 0; while (n > 0) { count += n & 1; n >>= 1; } return count; } const n = 95; // 0101 1111 const count = Count1Bit(n); console.log("Number of 1 bit = " + count); /* run: "Number of 1 bit = 6" */