I've a sensor that delivers its 16bits in this way : 1. MSB 2. LSB :
The values are in this range :
0xffff ===> -32767 MIN
0x8000 ====> -1 LSB say -1
0x0000 ====> +1 LSB say 1
0x7FFF ====> 32767 MAX
I'm trying to display these values in a readable way. For that I've written this small program:
#include <stdio.h>
#include <math.h>
#include <stdint.h>
int main(){
char msbyte =0x7f;
char lsbyte = 0xff;
int16_t temp=0;
temp = (msbyte<<8) | lsbyte;
printf(" %4x temp %d ", temp,temp);
return 0 ;
}
the result that I get is strange:
ffffffff temp -1
I expected the output to be:
7fff temp 32767
What am I doing wrong?