cmp the two funcs' style and gain some coding experience:
- int count_one_bits(unsigned value)
- {
- int one;
- /*
- *when the value still have some '1'
- * */
- for(one = 0;value !=0 ;value = value >> 1)
- {
- if(value % 2 != 0)
- {
- one = one + 1;
- }
- // return one;
- }
- return one;
- }
- int count_one_bits_2(unsigned value)
- {
- int one;
- /*
- *when the value still have some '1'
- * */
- for(one = 0;value !=0 ; value >>= 1)
- {
- if((value & 1) != 0)
- {
- one = one + 1;
- }
- // return one;
- }
- return one;
- }
阅读(777) | 评论(0) | 转发(0) |