不能溢出的话,将高位1对齐再判断也可以。
#include <stdio.h>
unsigned int _bitlshift(unsigned int n)
{
if (n == 0)
return 0;
unsigned bits=8*sizeof(unsigned int)-1;
while (((n>>bits)&1) == 0)
n <<= 1;
return n;
}
main()
{
unsigned m, n;
scanf("%u%u",&m,&n);
if (_bitlshift(m) == _bitlshift(n))
printf("yes");
else
printf("no");
}
[此贴子已经被作者于2017-1-2 16:03编辑过]