Zoj 2417 lowest Bit (Simple simulation)

Source: Internet
Author: User
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  ;} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.