I am having a really difficult time figuring this out.
I am pulling data from a device that produces values both positive and negative, the data is output in hex.
I use a function like this to convert the hex into decimal:
msg.payload = parseInt(msg.payload, 16);
this works just fine when the numbers are positive for example 0x00000f = 15, but when the numbers are negative values - the hex to decimal changes to something like 0xfffffff1 = 4294967281.
Now I know this is because of a decimal from signed 2's complement (because the hex converter I found online said so), and shows the value -15.
I tried looking how to calculate this value correctly to give me a negative number - I saw an answer online that said to write the function like this:
msg.payload = ~~parseInt(msg.payload,2)// == -3;
However that just returns the value 1
I am in way too deep to figure this out on my own....so I'm hoping someone can help me out.