Java Bit Count bitCount(int i)

Here you can find the source of bitCount(int i)

Description

bit Count

License

Open Source License

Declaration

static int bitCount(int i) 

Method Source Code

//package com.java2s;

public class Main {
    static int bitCount(int i) {
        if (i == 0) {

            return 32;

        }//from  w ww  .  j a va 2s .  co m

        int j = i;
        int n = 0;

        while (j != 0) {
            j &= (j - 1);
            ++n;
        }

        return n;
    }
}

Related

  1. bitCount(byte b)
  2. bitCount(final Integer i)
  3. bitcount(int num)
  4. bitCount(int x)
  5. bitCount(String s)
  6. bitCountSlow(int x)