Title Description
Function: To find a byte number corresponding to the binary number 1 of the maximum consecutive number, such as 3 of the binary 00000011, the maximum continuous 2 1
Input: A byte-type number
Output: None
Returns: The maximum number of consecutive digits in the corresponding binary number 1
Enter a description
Enter a byte number
Output description
The number of consecutive 1 after the output turns into binary
Input sample
3
Output sample
2
Problem analysis
You can find the maximum number of consecutive 1 for the right edge of the digital edge.
Test code
1#include <stdio.h>2 3 intMainvoid)4 {5 intnum, Count =0, max =0;6 7 while(SCANF ("%d", &num)! =EOF)8 {9Count = max =0;Ten while(num) One { A if(Num &1) - { -count++; theMax = (Count > Max)?Count:max; - } - Else - { +Count =0; - } +Num >>=1; A } atprintf"%d\n", max); - } - return 0; -}
To find the maximum number of consecutive bits