Java Program to display Bit manipulation in Integer

Java 8Object Oriented ProgrammingProgramming

Let’s say we have the following decimal number, which is binary 100100110.

int dec = 294;

To perform bit manipulation, let us count the number of 1 bits in it. We have used bitCount() method for this purpose.

Integer.bitCount(dec);

The following is an example to display bit manipulation in given Integer.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      // binary 100100110
      int dec = 294;
      System.out.println("Count of one bits = " + Integer.bitCount(dec));
   }
}

Output

Count of one bits = 4
raja
Published on 13-Nov-2018 05:09:05
Advertisements