Store frequency of number of set bits for s1
for ( int i = 0 ; i < s1 . Length ; i ++ ) { int set_bits = Convert . ToString ( ( int ) s1 [ i ] , 2 ) . Count ( c => c == '1' ) ; arr1 [ set_bits ] ++ ; }