Here you can find the source of countBits(int mask)
private static int countBits(int mask)
//package com.java2s; /****************************************************************************** * Copyright (c) 2004, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w ww . ja va 2 s . c om * IBM Corporation - initial API and implementation ****************************************************************************/ public class Main { private static int countBits(int mask) { int count = 0; for (int index = 0; index < 32; index++) { if ((mask & 0x1) != 0) { count++; } mask = mask >>> 1; } return count; } }