You can use strtoul()
with base 2 to convert the string to an unsigned integer:
NSString *bitSeries = @"00000000000000000000000111101100";
uint32_t value = strtoul([bitSeries UTF8String], NULL, 2);
and then create an NSData
object:
NSData *data = [NSData dataWithBytes:&value length:sizeof(value)];
NSLog(@"%@", data);
// Output: <ec010000>
Or, if you prefer big-endian byte order:
value = OSSwapHostToBigInt32(value);
NSData *data = [NSData dataWithBytes:&value length:sizeof(value)];
NSLog(@"%@", data);
// Output: <000001ec>