Hi,
I does not have programming background. In the following Obj-C code i create an array of bytes but i must convert bytes into string Hex format to work further. It is not a good idea. So i would like to create an array in C directly without converting to string. How can i do it? Thank you!
Something like this in Obj-C + C:
NSData *data = [NSData dataWithContentsOfFile:file];
const unsigned char *bytes = [data bytes];
for (int i = 0; i < [bytes count]; i++) {
unsigned char array = (int)bytes; // Something like this in C
}
printf("array: %d", array);
I does not have programming background. In the following Obj-C code i create an array of bytes but i must convert bytes into string Hex format to work further. It is not a good idea. So i would like to create an array in C directly without converting to string. How can i do it? Thank you!
Something like this in Obj-C + C:
NSData *data = [NSData dataWithContentsOfFile:file];
const unsigned char *bytes = [data bytes];
for (int i = 0; i < [bytes count]; i++) {
unsigned char array = (int)bytes; // Something like this in C
}
printf("array: %d", array);
PHP:
NSData *data = [NSData dataWithContentsOfFile:file];
const unsigned char *bytes = [data bytes];
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < [bytes count]; i++) {
NSString *bytesAsString = [NSString stringWithFormat:@"%02x", (int)bytes[i]];
[array addObject:bytesAsString];
}
NSLog(@"%@", array);