Java Program to display Bit manipulation in Integer


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

Updated on: 26-Jun-2020

182 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements