开发者

appending data using NSMutableData

开发者 https://www.devze.com 2023-02-09 09:28 出处:网络
Right now I\'m appending data using NSMutableData\'s -appendBytes:length: like this: in开发者_运维技巧t length = [self.trackData length]+3;

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

精彩评论

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