문제

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 ?

도움이 되었습니까?

해결책

Got it working this way

+ (int) dataToIntSwitched:(NSMutableData*) data
{
    int elem = OSReadLittleInt([data bytes], 0);
    return elem;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top