lonelysoul

Happy share, happy life.

导航

iOS——二进制转十进制

- (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] ;
}

 

 

祝您愉快开心 ^_^

posted on 2013-11-09 19:58  lonelysoul  阅读(182)  评论(0编辑  收藏  举报