Let me rephrase your post to check my understanding.
Your result is "ebf" whereas you were expecting "eb0f", right ?
Indeed, when converting a number to a string many times you want the end result to be padded with zeroes to have a fixed amount of digits. The easiest way is to use the JavaScript (ES6) method padStart().
let a = 0x1f;
let b = a ^ 0x10;
node.warn(b.toString(16));
let c = b.toString(16).padStart(2,"0");
node.warn(c);
return msg;
The above code shows the number 0x1f
being stored in the variable a
, then xored with 0x10
and stored in the variable b
.When you represent the content of the variable b
using toString(16) it will produce the string f
, which is bad for you. The solution: using the method padStart() to add the "missing" zero in front of the result. You will get the string 0f
stored in the variable c
.
Testing flow:
[{"id":"9d9973da.b582d","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"fc8e586.700cca8","type":"function","z":"9d9973da.b582d","name":"padStart","func":"let a = 0x1f;\nlet b = a ^ 0x10;\nnode.warn(b.toString(16));\n\nlet c = b.toString(16).padStart(2,\"0\");\nnode.warn(c);\n\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":180,"wires":[[]]},{"id":"d1a62239.fce05","type":"inject","z":"9d9973da.b582d","name":"Go","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":180,"wires":[["fc8e586.700cca8"]]}]
Debug Panel:
Final remarks: There are a coupe of things that seems strange in your code example but I just disregarded them to keep focus on the main point that is how to represent an hexadecimal number in a string with two digits.