fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int ret_one_bit_num(unsigned int);
  4. void main(){
  5. int rlt = 0, input = 9;
  6.  
  7. rlt = ret_one_bit_num(input);
  8. printf("%d have [%d] bit is 1\r\n", input, rlt);
  9. system("pause");
  10. }
  11. int ret_one_bit_num(unsigned int n)
  12. {
  13. int count = 0;
  14. while(n!=0)
  15. {
  16. if(n & 1 == 1)
  17. count++;
  18. n>>=1;
  19. }
  20. return count;
  21. }
Success #stdin #stdout #stderr 0s 9432KB
stdin
Standard input is empty
stdout
9 have [2] bit  is 1
stderr
sh: 1: pause: not found