Convert 2 bytes into an integer
I receive a port number as 2 bytes (least significant byte first)
You can then do this:
int number = buf[0] | buf[1] << 8;
If you make buf
into an unsigned char buf[2];
, you can simplify it to:
number = (buf[1] << 8) + buf[0];