Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 254
Ruchit Patel Avatar asked Dec 01 '22 03:12

Ruchit Patel


1 Answers

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.

like image 184
Dave DeLong Avatar answered Dec 05 '22 03:12

Dave DeLong