开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜