this implementation is based on strings . transforming an integer into the binary representation we can obtain an string and use it to count the number of elements equals to ' 1 ' . this implementation is slow because it 's based on transform the parameter into the binary representation which complexity order is o n where n is the number of digits in the parameter binary representation . in addition we have to count the number of elements inside the string obtained and the complexity order of that operation is again o n . in space terms , the complexity order is o n where n is the number of digits used to represent the parameter using binary format . this cost is associated to the usage of an auxiliary string to keep the binary result . to get the binary representation we are going to use a static method of integer class : integer.tobinarystring . concode_field_sep PlaceHolder placeHolder concode_field_sep int countBitsToOneBasedOnBinaryOperators
int function ( int arg0 ) { int loc0 = 0 ; String loc1 = Integer . toBinaryString ( arg0 ) ; for ( char loc2 : loc1 . toCharArray ( ) ) { loc0 += loc2 == '1' ? 1 : 0 ; } return loc0 ; }