Given a positive integer num
, determine the number of set bits (1s) present in the binary representation of the given number, commonly referred to as the Hamming weight.
num: number
: A positive integerInput: num = 8Output: 1Explanation: The given number in binary (1000) has a total of one set bit
Input: num = 9Output: 2Explanation: The given number in binary (1001) has a total of two set bit
Input: num = 123Output: 6Explanation: The given number in binary (1111011) has a total of six set bit
num
<= 2^31 - 1Given a positive integer num
, determine the number of set bits (1s) present in the binary representation of the given number, commonly referred to as the Hamming weight.
num: number
: A positive integerInput: num = 8Output: 1Explanation: The given number in binary (1000) has a total of one set bit
Input: num = 9Output: 2Explanation: The given number in binary (1001) has a total of two set bit
Input: num = 123Output: 6Explanation: The given number in binary (1111011) has a total of six set bit
num
<= 2^31 - 1console.log()
statements will appear here.