I stored the data bytes in an Array. Now, in the program I used getBytes:range:NSmakeRange(position, length). When I printed my received bytes I think their position got swapped and my answer was 0x0292 instead of 0x9202 (check my program below).
Now, I am confused on which one is the correct answer. Is it really necessary for me to always swap the bytes that I received. Please explain to me this concept so that I can understand in a clear way.
Here is my code!! Thank you.
const Byte dataBytesArray[] = {
0x92, 0x02, 0x13, 0x14 //in Hex
};
NSData *myDataArray = [[NSData alloc]initWithBytes:dataBytesArray length:4];
uint16_t ef;
[myDataArray getBytes:&ef range:NSMakeRange(0, 2)];
NSLog(@"dataByteArray is %@ ",[NSNumber numberWithUnsignedInteger:ef]);//the answer I got is 658 in decimal format which is 0x0292
uint16_t swapping = CFSwapInt16BigToHost(ef); //swapping the bytes
NSLog(@"swap is %@ ",[NSNumber numberWithUnsignedInteger:swapping]); //after swapping I got 37378 which is 0x9202