二进制转十进制

2016-05-25  本文已影响74人  iOS_Rainbow

- (NSInteger)toDecimalSystemWithBinarySystem:(NSString *)binary

{

int ll = 0 ;

int temp = 0 ;

for (int i = 0; i < binary.length; i ++)

{

temp = [[binary substringWithRange:NSMakeRange(i, 1)] intValue];

temp = temp * powf(2, binary.length - i - 1);

ll += temp;

}

NSString * result = [NSString stringWithFormat:@"%d",ll];

return [result integerValue] ;

}

上一篇 下一篇

猜你喜欢

热点阅读