Number of One bits-Asked in Interviews

Placewit
Jan 8, 2022

--

Problem Statement :

Given a positive integer N, print count of set bits in it.

Input Format:

The input contains one line containing the number ‘N’.

Output Format:

The output consists of one line consisting of the number of 1s in the binary representation of ‘N’.

Given:

8

Output:

2

Explanation of Test case:

Binary representation of 6 is '110' 
So the count of the set bit is 2.

Approach:

Convert the N into binary representation and count the 1's.

Code:

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

Placewit
Placewit

Written by Placewit

Upskilling students for tech placements!

No responses yet