Officially announcing node-red-contrib-bitunloader! This is a tool that's useful for those who are working with integer values received from modbus or similar protocols. Pass in a value that is or can be parsed as an Integer and it will spit out the binary form of that number with a few different formats to choose from.
Bitunloader works beautifully to convert a number into an array of 16 bits but I need to find a node that can do exactly the opposite. What is the best way to convert an array of 16 bits into a number?
I'd look at either array.forEach() or array.reduce() to get a binary string that you could pass into parseInt() to get an integer number again. I've thought about adding a "reloader" node that could automatically handle this function. I'll look at it if I ever find the time!
Start with a value of zero, then loop through the array, most significant bit first, and for each one shift the accumulated value left one bit and add in the value from the array.
Hey there, thought I'd just let you know I've updated this to include a node for reversing the bitunloader node. It works using a couple properties passed from the bitunloader to tell it what to do, but you could also generate these yourself to use the bitreloader node stand-alone.