/** * Quickly calculate the number of 1 of 1 in the number of binary numbers * The idea of the algorithm is as follows: * Each time the number is reduced with the value after the number is reduced, so as to the one on the far from the right side 1 1 The number of times that the number of the number is 0* in the middle cycle is the number of 1 of them* For example, "given" 10100 "," 10011 "after subtraction, and" 10000 ", so as to eliminate the most on the far right side 1 * Sparse One and Dense ONes WERERST DESCRIBED by Peter Wegner in * "A Technique for Counting One in A BINARY Computer", * Communications of the Acm, Volume 3 (19 60) Number 5, Page 322 */ Package Al; Public Class Countones {Public Static Void Main (String [] Args) {int i = 7; Countings Count = New Countones (); System.out.println ("There are" + Count.GetCount ( i) + "one in i")) ;} / *** @AutHor* @param I to be tested.* @Return Dual indication The number of 1 is* / Public Int GetCount (int i) {int n; for (n = 0; i> 0; n ++) {i & = (i -1);} Return n;}}