将二进制二进制补码数据转换为objective-c中的整数

我有一些二进制数据(二进制补码)来自加速度计,我需要将其转换为整数。 是否有标准的库函数来执行此操作,还是需要编写自己的代码?

例如:我从acclerometer接收一个NSData对象,当转换为hex时,如下所示:

C0088001803F 

这是3个2字节数据块的串联:

 x = C008 y = 8001 z = 803F 

仅关注x轴:

 hex = C008 decimal = 49160 binary = 1100000000001000 twos complement = -16376 

是否有标准function可以将二进制补码中的C008直接转换为-16376?

谢谢。

就像是:

 const int8_t* bytes = (const int8_t*) [nsDataObject bytes]; int32_t x = (bytes[0] << 8) + (0x0FF & bytes[1]); x = x << 16; x = x >> 16; int32_t y = (bytes[2] << 8) + (0x0FF & bytes[3]); y = y << 16; y = y >> 16; int32_t z = (bytes[4] << 8) + (0x0FF & bytes[5]); z = z << 16; z = z >> 16; 

这假定值确实是问题中建议的“大端”。