Vu le code Java suivant pour générer un fichier binaire:Comment analyser un fichier binaire avec des flottants (généré en Java) en utilisant Cocoa Touch?
DataOutputStream out = new DataOutputStream(new FileOutputStream("foo.dat"));
out.writeInt(1234);
out.writeShort(30000);
out.writeFloat(256.384f);
J'utilise le code suivant Objective-C et de gérer pour analyser l'int et les valeurs courtes:
NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"dat"];
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path];
unsigned long intValue;
memcpy(&intValue, [[file readDataOfLength:4] bytes], 4);
intValue = NSSwapBigLongToHost(intValue);
unsigned short shortValue;
memcpy(&shortValue, [[file readDataOfLength:2] bytes], 2);
shortValue = NSSwapBigShortToHost(shortValue);
Mon problème pour l'instant est avec la valeur float: des indices sur la façon de l'analyser?