implemented bit count algorithm