package com.harrison.Class01; public class Code09_BitOneCounts { public static int bit1Counts(int n) { int count=0; while(n!=0) { int rightOne=n&((~n)+1); count++; n^=rightOne; } return count; } public static void main(String[] args) { int n=171;//10101011 System.out.println(bit1Counts(n)); } }