MCPcopy Create free account
hub / github.com/careercup/ctci / countOnes

Method countOnes

java/Chapter 5/Question5_3/Question.java:5–14  ·  view source on GitHub ↗
(int i)

Source from the content-addressed store, hash-verified

3public class Question {
4
5 public static int countOnes(int i) {
6 int count = 0;
7 while (i > 0) {
8 if ((i & 1) == 1) {
9 count++;
10 }
11 i = i >> 1;
12 }
13 return count;
14 }
15
16 public static int countZeros(int i) {
17 return 32 - countOnes(i);

Callers 3

countZerosMethod · 0.95
getNextSlowMethod · 0.95
getPrevSlowMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected