int main(int argc, char * argv[])
{
@autoreleasepool
{
NSMutableArray* result=[NSMutableArray new]; int number=160; while (number != 0) { /** * 求商 */ if (number==0) { break; } else { /** * 偶数 */ if(number%2==0) { [result addObject:@(0)]; }//奇数 else { [result addObject:@(1)]; } } /** * 右移 */2 */ number = number>>1; } NSLog(@"%@",result); NSArray* reversedArray = [[result reverseObjectEnumerator] allObjects]; NSLog(@"倒序 %@",reversedArray); return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }
截图
参考: