Lowest Bit
Time limit:2 seconds Memory limit:65536 KB
Given an positive integer A (1 <= A <= 100), output the lowest Bit Of.
For example, given a = 26, we can write a in binary form as 11010, so the lowest Bit Of A is 10, so the output shocould be 2.
Another example goes like this: Given A = 88, we can write a in binary form as 1011000, so the lowest Bit Of A is 1000, so the output shocould be 8.
Input
Each line of input contains only an integer A (1 <= A <= 100 ).
A line containing "0" indicates the end of input, and this line is not a part of the input data.
Output
For each A in the input, output a line containing only its lowest Bit.
Sample Input
26
88
0
Sample output
2
8
Analysis:
(1) because it is a number less than 100, you only need to find all the binary numbers that can constitute less than 100, and then subtract them once until the value is 0, which indicates that the number is the minimum valid bit.
# Include <stdio. h> Int Main (){ Int N, bit_num [ 7 ], I; // A combination of binary numbers less than 100 can be obtained. Bit_num [ 0 ] =1 ; For (I = 1 ; I < 7 ; I ++ ) Bit_num [I] = Bit_num [I- 1 ] * 2 ; While (Scanf ( " % D " , & N )! = EOF & n! = 0 ){ For (I = 6 ; I> = 0 ; I -- ){ If (N> = Bit_num [I]) N -= Bit_num [I]; If (N = 0 ) Break ;} Printf ( " % D \ n " , Bit_num [I]);} Return 0 ;}