appending data using NSMutableData
Right now I'm appending data using NSMutableData's -appendBytes:length: like this:
in开发者_运维技巧t length = [self.trackData length]+3;
[contents appendBytes:&length length:4];
Suppose length is 20. In hex, the bytes appended are 16 00 00 00, extended to 4 bytes. How can I add the additional zeros to the left like in 00 00 00 16?
You probably want to swap the bytes to big-endian:
int length = NSSwapHostIntToBig([self.trackData length]+3);
[contents appendBytes:&length length:4];
精彩评论