I have 16 boolean variables that I want to send like an int16 type value.
Is it possible to do it with a function node? How?
Yes.
How are these 16 boolean values stored? In named properties of an object? in an array? are they actual bools or strings or ones and zeros? etc etc (the devil is in the detail)
for example: an array could be processed like this:
let booleanArray = msg.payload
// test data for demonstration purposes (delete me)
booleanArray = [true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false]
msg.payload = booleanArray.reduce((acc, currentValue, index) => {
return acc | (currentValue ? 1 << index : 0)
}, 0);
return msg
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.