fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdint.h>
  4. int main(){
  5. unsigned char msbyte =0xff;
  6. unsigned char lsbyte = 0xff;
  7. uint16_t temp=0;
  8. int16_t num16=0;
  9. temp = (msbyte<<8) | lsbyte;
  10. num16 = (int16_t)(temp & 0x7FFF);
  11. if(temp & 0x8000) { /* Get sign bit */
  12. num16 = num16 * -1 - 1;
  13. }
  14. printf(" %4x temp %d ", temp,num16);
  15.  
  16. return 0 ;
  17.  
  18. }
  19.  
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
 ffff temp -32768