HDOJ 1196
http://acm.hdu.edu.cn/showproblem.php?pid=1196
Problem Description
Given 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.
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
#include <iostream>
using namespace std;
int main()
{
int m,n;
while(cin>>m&&m)
{
n=m&-m;
cout<<n<<endl;
}
return 0;
}
对于8进制和负数能举几个例子吗~谢谢
追答比如-26怎么求它的补码呢
第一步:写出26的的二进制原码表示为:00011010,补码不变也是00011010
第二步:写出-26的二进制原码表示为:10011010其中最高位的1表示它是负数
第三步:写出-26的二进制反码表示为:11100101
第四步:写出-26的二进制补码表示为:11100101+1变为11100110
然后26&-26=00011010&11100110=00000010(按位取&得结果)用十进制表示就是2