Computer Science, asked by ppadmaja130147, 8 months ago

Given an integer, say N. You need to find the following.
1. The number of set bits (bits that are 1 in the bitwise representation) in N
2. The position of the least significant set bit
3. The position of the most significant set bit
The output should be a string of the form: a#b#c, where a, b, care answers for the above
three queries respectively,
Inn​

Answers

Answered by gollapallipavani31
8

Answer:

2#1#3

Explanation:

The position of the least significant set bit

3. The position of the most significant set bit

The output should be a string of the form: a#b#c,

Answered by steffiaspinno
2

1) The number of set bits (bits that are 1 in the bitwise representation) in N

Output = 2

Java program

import java.io.*;

class countSetB

{

 static int countSetB(int N)

   {

       int count = 0;

       while (N > 0)

{

           count = count + N & 1;

           N >>= 1;

       }

       return count;

   }

   public static void main(String args[])

   {

       int j = 6;

       System.out.println(countSetB(j));

   }

}

Similar questions