I am trying to obtain a binay numer (instead string) bacause I would like to obtain n.4 outputs, one for each bit, hoping that the code:
var m0 = msg.payload & 0x01;
var m1 = msg.payload & 0x02 >>> 1;
var m2 = msg.payload & 0x04 >>> 2;
var m3 = msg.payload & 0x08 >>> 3;
return [{payload:m0},{payload:m1},{payload:m2},{payload:m3}];
can give me n.4 outputs.
I'm doing something too difficult for me and I don't want to disturb or upset anyone.
I will continue to do tests. Thank you and sorry for the inconvenience.
I did it, thanks for you suggestions:
msg.payload = parseInt("0x"+msg.payload);
msg.payload = msg.payload.toString(2).padStart(4, '0');
var m0 = msg.payload.split(' ')[0].substr(0,1);
var m1 = msg.payload.split(' ')[0].substr(1,1);
var m2 = msg.payload.split(' ')[0].substr(2,1);
var m3 = msg.payload.split(' ')[0].substr(3,1);
return [{payload:m0},{payload:m1},{payload:m2},{payload:m3}];
1 Like
var m0 = (msg.payload.output & 0x01);
var m1 = (msg.payload.output & 0x02) >>> 1;
var m2 = (msg.payload.output & 0x04) >>> 2;
var m3 = (msg.payload.output & 0x08) >>> 3;