Here you can find the source of countBits(long value)
public static int countBits(long value)
//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; } }