Java Bit Count countBits(int x)

Here you can find the source of countBits(int x)

Description

count Bits

License

Open Source License

Declaration

public static int countBits(int x) 

Method Source Code

//package com.java2s;
//The MIT License

public class Main {
    public static int countBits(int x) {
        x = (x & 0x55555555) + ((x >> 1) & 0x55555555);
        x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
        x = (x & 0x0f0f0f0f) + ((x >> 4) & 0x0f0f0f0f);
        x = (x & 0x00ff00ff) + ((x >> 8) & 0x00ff00ff);
        x = (x & 0x0000ffff) + ((x >> 16) & 0x0000ffff);
        return x;
    }/*from   w w  w.  ja  v a2 s . c om*/
}

Related

  1. countBits(final int intValue)
  2. countBits(int i)
  3. countBits(int mask)
  4. countBits(int n)
  5. countBits(int x)
  6. countBits(long num)
  7. countBits(long value)
  8. countBitsInMask(int mask)
  9. countBitsNeeded(int value)