Hello,
I have a binary file, and I also know what each byte represents.
I can read the file, convert it to bytes and acces each byte separately.
There are several blocks of bytes which should be converted to meaningful data, some blocks are strings, some are floats, etc.
I am looking for functions to help with this. More specifically how to copy part of this bytes array into a new smaller array.
So far, I came across methods to add new bits to an array, or how to copy the array completely.
Converting to a string should not be a problem. NSString has a function to convert bytes to a string:
+ (id)stringWithCharactersconst unichar *)chars lengthunsigned)length
Converting to a float is probable also not difficult, I guess.
Also, I am a bit concerned about memory management.
If I start making many const char arrays, how will this affect good memory management.
I am more used to the higher level cocoa code: init, alloc, release.
Thanks!
I have a binary file, and I also know what each byte represents.
I can read the file, convert it to bytes and acces each byte separately.
Code:
//retrieve data
NSData *data = [NSData dataWithContentsOfFile:@"filename.ext"];
const unsigned char *bytes = [data bytes];
//header
int j;
for (j=0; j <99;j++) {
NSLog(@"%i %i _%c_",j, (int)bytes[j],(int)bytes[j]);
}
There are several blocks of bytes which should be converted to meaningful data, some blocks are strings, some are floats, etc.
I am looking for functions to help with this. More specifically how to copy part of this bytes array into a new smaller array.
So far, I came across methods to add new bits to an array, or how to copy the array completely.
Converting to a string should not be a problem. NSString has a function to convert bytes to a string:
+ (id)stringWithCharactersconst unichar *)chars lengthunsigned)length
Converting to a float is probable also not difficult, I guess.
Also, I am a bit concerned about memory management.
If I start making many const char arrays, how will this affect good memory management.
I am more used to the higher level cocoa code: init, alloc, release.
Thanks!