Nguyên văn bởi phuongdua
Xem bài viết
Code:
// testbench.c unsigned char Counter( unsigned int test_num); int main() { unsigned int test_num = 232; unsigned char num_1s = Counter(test_num); return 0; }
Code:
// Counter.c unsigned char Counter( unsigned int test_num) { unsigned char count = 0; unsigned int temp = test_num; unsigned char max = 0; while (temp >0) { if((temp %2)==1) count ++; else { if(count > max) max = count; count = 0; } temp = temp >> 1; } return max; }
Comment