Java Bit Count countBits(long value)

Here you can find the source of countBits(long value)

Description

count Bits

License

BSD License

Declaration

public static int countBits(long value) 

Method Source Code

//package com.java2s;
/**//from  w ww  .  j  a  v  a  2 s.c  om
 * Copyright (C) 2011-2013 Barchart, Inc. <http://www.barchart.com/>
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */

public class Main {
    public static int countBits(long value) {

        int count = 0;

        while (value > 0) {
            value >>= 1;
            count++;
        }

        return count;

    }
}

Related

  1. countBits(int mask)
  2. countBits(int n)
  3. countBits(int x)
  4. countBits(int x)
  5. countBits(long num)
  6. countBitsInMask(int mask)
  7. countBitsNeeded(int value)
  8. countBitsSet(int bitfield)