Take FFC4. In decimal it is converted to: 65476, I want it to be read as -60, which is the decimal from signed 2's complement.
I could not find the mentioned by you formula in the device's datasheet. I am taking the RSSI from a Bluetooth Module HC-05 which is connected to an Arduino Nano. Sorry if I am a bit unclear, electronics are not my field of expertise.
if the variable your place FFC4 into is a uint16_t (unsigned integer on arduino UNOs and similar) then yes, it is 65476
if you place the same hex number into an int16_t (signed int on arduino UNOs) then the value is -60.
If I understand the HC-05, these hex numbers arrive over the serial connection as part of a longer status message, so are really text strings like "FFC4" or "FFCG".
So I think the OP is trying to convert a text representation of a hexadecimal number to a numeric value.
GypsumFantastic:
If I understand the HC-05, these hex numbers arrive over the serial connection as part of a longer status message, so are really text strings like "FFC4" or "FFCG".
So I think the OP is trying to convert a text representation of a hexadecimal number to a numeric value.
Of course, if he's getting a value like FFCG, then we're talking base 17 (at least). In which case both numbers are positive anyway, so two's compliment does not apply.
However, it does not really matter. The top two bytes are getting tossed anyways.
strtol and strtoul will both return the same thing when you give it a two byte hex number, no matter what the size. (Unless it's been a longer day than I though and I'm totally wrong.)