Converting unsigned chars to signed integer

前端 未结 4 2230
轻奢々
轻奢々 2021-02-09 20:11

I have an unsigned char array with 2 elements that represents a signed integer. How can I convert these 2 bytes into a signed integer?

Edit: The unsigne

4条回答
  •  粉色の甜心
    2021-02-09 20:38

    wrap them up in a union:

    union {
      unsigned char a[2];
      int16_t smt;
    } number;
    

    Now after filling the array you can use this as number.smt

提交回复
热议问题