Number of 1s in a n-bit register ♠ Posted by GeekyFry in algorithm,C,data-structures,interview,programming,tech-it at 6:31 AM How to find the number of ‘1s’ in a n-bit register. Write code. Possible Solution: 1 2 3 4 5 6 7 8 9 10 int count(reg_type t) { int i = 0; while (t) { t = t & (t-1); ++i; } return i; }

## 0 comments:

## Post a Comment