Contact: aviboots(AT)netvision.net.il
39,959 questions
51,901 answers
573 users
function count_set_bits(n: number) { let count: number = 0; while (n) { count += n & 1; n >>= 1; } return count; } const n: number = 793; // 0011 0001 1001 console.log(count_set_bits(n)); /* run: 5 */
function count_set_bits(n: number) { let count: number = 0 for (; n; n >>= 1) { count += n & 1; } return count; } const n: number = 793; // 0011 0001 1001 console.log(count_set_bits(n)); /* run: 5 */