有數值按此方式構成:
5=2^0+2^2;
40=2^3+2^5;
現在需要獲取到冪值0和2或者3和5。int main(int argc, char * argv[])
intmain(intargc,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])); } }