0

I have an NSData object whose contents are raw bytes looking something like this:

1e050014 c8d7b452 28f98c72 e95748b9 2801086b e85b07b9 2c010054 01000014
88c9b452 68878a72 e95748b9 2801086b e85707b9 20030154 10050014 a84bb552 
c8299a72 e95748b9 2801086b e85307b9 2c010054

I'm trying to put these in a string array as is and this hasn't worked and returns an empty array:

NSData* data0 = [NSData dataWithContentsOfFile:str0];//this contains the bytes well 
NSMutableArray *array = [NSMutableArray arrayWithCapacity:data0.length];

This doesn't work either:

const char* fileBytes = (const char*)[data0 bytes];

for (int i = 0; i < data0.length; i++) {
    UInt8 byteFromArray = fileBytes[i];
    [array addObject:@(byteFromArray)];
}

How can I put the raw bytes into a string array without interpreting the raw bytes as strings?

j.doe
  • 3
  • 5
  • https://stackoverflow.com/questions/7520615/how-to-convert-an-nsdata-into-an-nsstring-hex-string ? – Larme Jul 27 '17 at 16:00
  • Thanks! it didn't give me the answer but it lead me down a better path and now I have a string of the bytes I needed and I'm assuming making it into an array isn't going to be much harder. – j.doe Jul 27 '17 at 17:00

0 Answers0