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!