有数值按此方式构成:
5=2^0+2^2;
40=2^3+2^5;
现在需要获取到幂值0和2或者3和5。int main(int argc, char * argv[])
int main(int argc, char * argv[])
{
@autoreleasepool { int bit = 0; int number=40; while (number != 0) {
//取余 int i = number %2;
if(i == 1) { printf("2^%d\n", bit); } /** * 右移除2,左移乘2 十进制位移运算 */ number = number>>1; bit ++; } return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }