Converting 16-bit, little-endian, 2's complement integer to regular integer
23 次查看(过去 30 天)
显示 更早的评论
I'm trying to get various data sets (accelerometer, gyroscope etc.) from a AHRS (a CHR-UM6) and I'm having trouble getting the values out in the correct form. The data received (for each value) is a two row column vector such as:
247
255
These numbers are 16-bit, little-endian, 2's complement and I need to get the actual value. I hope someone can help!
Thanks, Ben
0 个评论
采纳的回答
Walter Roberson
2015-6-12
swapbytes(typecast(TheByteVector, 'int16'))
TheByteVector should be uint8.
2 个评论
Walter Roberson
2015-6-14
gyro_x = double(typecast(uint8(packet.data([2 1]),'int16')) * 0.0610352;
No need to call swapbytes if you don't need to ;-)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sensor Models 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!