Convert Binary to Decimal in Objective C
问题 I have binary sequence in a string. How to convert it in decimal. Is there any built in function in Objective C ? 回答1: NSString * b = @"1101"; long v = strtol([b UTF8String], NULL, 2); NSLog(@"%ld", v); //logs 13 The downside of this is that it only appears to produce positive numbers. 回答2: I couldn't find any built in function. So wrote simple C function according to the process we do for conversation. (int) BinToInt(char *temp) { int count, total, i, j, tmp; total = 0; count = strlen(temp);