I want to read Data via node red modbus node from a data source. The range is -20000 to 20000, but the node cannot handle negative numbers, so I had to convert them to binary numbers (DWORD), split them in the lower and higher word and convert these words back to integers.
var low
function dec2bin(dec){
return (dec >>> 0).toString(2);
}
var a = msg.payload
if (a >= 0){
a = dec2bin(a);
a = parseInt(a,2);
} else {
a = dec2bin(a);
a = a.substr(16);
a = parseInt(a,2);
}
low = { payload: a };
return low;
For visualisation I want to use the dashboard nodes, but therefor I need to join the 2 binary strings together and convert them to an int.
Problem:
node red converts them as a qword, so the binary number 1111 1111 1111 1111 1111 1100 0001 1000 is seen as 4.294.966.296, not as -1000. But if i fill the next rest with 1 lime so: 1111 1111 1111 1111 1111 1111 1111 1111 1111 1100 0001 1000 puts out 18446744073709552000
Thanks