(hdu 簡單題 128道)Lowest Bit(求一個數的二進位的最後一個非零位對應的十進位數),hdulowest

來源:互聯網
上載者:User

(hdu 簡單題 128道)Lowest Bit(求一個數的二進位的最後一個非零位對應的十進位數),hdulowest

題目:

Lowest BitTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8722    Accepted Submission(s): 6428


Problem DescriptionGiven an positive integer A (1 <= A <= 100), output the lowest bit of A.

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 should 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 should be 8.
 
InputEach 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.
 
OutputFor each A in the input, output a line containing only its lowest bit.
 
Sample Input

26880
 
Sample Output
28
 
AuthorSHI, Xiaohan 
SourceZhejiang University Local Contest 2005 
RecommendIgnatius.L   |   We have carefully selected several similar problems for you:  1200 1201 1008 1004 1106 


題目分析:

                簡單題。在將10進位數轉換成2進位數的過程中不斷地判斷當前位是否是非零位即可。


相應的知識點:

在這時候可能需要回顧一下10進位轉2進位的過程:




代碼如下:

/* * d.cpp * *  Created on: 2015年3月11日 *      Author: Administrator */#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){int n;while(scanf("%d",&n)!=EOF,n){int t = 0;while(n%2 == 0){t++;n /= 2;}printf("%d\n",(int)pow(2+0.0,t));}return 0;}




 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.