English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java program displays bit operations with integers

Assuming we have the following decimal number, that is, binary100100110.

int dec = 294;

To perform bit operations, let's calculate the1Bit count. WebitCount()This method is used for this.

Integer.bitCount(dec);

The following is an example of displaying bit operations on a given Integer.

Example

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

Output Result

Count of one bits = 4