Search code examples
objective-cnsmutabledata

NSMutableData replacing bytes


I'm trying to replace bytes in correct order (server sends them in bad order). And I'm having a hard time getting it done. Maybe someone could help me do this correctly

Input:  < F801 0020 > (NSMutableData)
Output: < 2000 01F8 > (NSMutableData)

Tried using replaceBytesInRange:<(NSRange)> withBytes:<(const void *)>

But I'm having a hard time using this method for this problem. Isn't there a simple method of swapping bytes in objective-c ?


Solution

  • Got it working this way

    + (int) dataToIntSwitched:(NSMutableData*) data
    {
        int elem = OSReadLittleInt([data bytes], 0);
        return elem;
    }