reverse order of bytes in NSData
never did this (except school). so i'm totally on the dark.
i have data (vo开发者_StackOverflow社区id *) and it's size (UInt32) so i can simply make something like
[NSData dataWithBytesNoCopy:data length:dataSize freeWhenDone:YES]
this to get a NSData instance (which i need), but i want "slice" the this data in 1 or 2 byte blocks and reverse it's order.
a short example would be great.
thx.
if you're struggling to find out what the heck is going on in the bytes during development,
typedef struct _SliceItUp
{
UInt8 a,b,c,d; // 4 x 8bits == 32 bits
}
SliceItUp;
SliceItUp dd;
[data getBytes:&dd length:sizeof(SliceItUp)];
NSLog(@"the four friends are %d %d %d %d", dd.a,dd.b,dd.c,dd.d);
You now have the four bytes individually as four totally distinct bytes.
You have total control and you can do whatever you want.
Check the documentation for the functions defined in NSByteOrder.h
精彩评论