2's complement question

Data is received in an array of 1 byte elements. The code to put two bytes into rptrTemp16 works fine. Is there a better way to do this?

The real issue is next - I read it into a 16 bit int first because if it's shifted into a long int, the high bit indicating a 2's complement negative number will no longer be the high bit.

I need to ultimately get it to a long int for some further math, but I'm not sure how a 2's complement, negative number is handled, and where and if the conversion to a negative number takes place.

Help is really appreciated. Thanks in advance.

int rptrTemp16;

long int rptrTemp32;

 
      rptrTemp16 = nrf_buf[4];
      rptrTemp16 = rptrTemp16 << 8;
      rptrTemp16 |= nrf_buf[3];

rptrTemp32 = rptrTemp16 //

If you have assembled rptrTemp16 correctly, conversion to a long is as simple as an assignment statement.

rptrTemp32 = rptrTemp16;

The sign of the number will be taken care of automatically.

Pete

It is assembled correctly, that part has been tested.

Thanks, Pete. That is what I needed to know.