Suppose I have a buffer filled with uint8_t, like what I would get by executing
uint8_t buffer[4];
[inputStream read:buffer maxLength:4];
Again, suppose I know that this buffer now contains two signed 16-bit integers in big-endian format (even though the type of the buffer is uint8_t). How would I go about getting the results of each of the numbers?
I think that you have to use bitwise operators, and that you have to also convert from unsigned to signed, but I can't seem to figure it out completely.
A similar example with only uint8_t values would look something like this:
uint8_t buffer[2];
[inputStream read:buffer maxLength:2];
uint8_t value1 = buffer[0];
uint8_t value2 = buffer[1];
Any help would be most appreciated, as I'm sure this is a relatively simple question.
Update: To further clarify the problem: I know in advance that I'm receiving numbers from 0 to 255, even though they are 16-bit signed. So any negative numbers received are incorrect, and should probably be shifted up by 127, to account for the signed/unsigned difference.