Hex Values
Estimated reading time: 1 minute
Function nodes can convert hexadecimal (hex) values into normal decimal integers. This is useful when performing operations on hex values.
Create the Flow
To create a flow to convert hex values to integers:
-
Connect an Inject node, a Function node, and a Debug node as pictured below in the final result.
-
Double-click the Function node and enter the following lines of code:
function hexToInt(hex) { // Declares a function, named hexToInt, for converting hex to integers. return parseInt(hex, 16); // Converts the hex into an integer by passing in 16 (for base 16) to parseInt. } var hex = msg.payload; // Saves the msg payload to pass into our function. var decimal = hexToInt(hex); // Calls the function to convert the hex into a decimal integer. msg.payload = "Hex: " + hex + ", Decimal: " + decimal; // Formats the text for output. return msg;
-
Click Done. Double-click the inject node and select string from the drop-down menu. Enter in any hex value to convert to an integer. This example uses 0x00A8, which is 168 as a decimal integer.
-
Click the button to the left of the inject node to view the output in the debug tab at the bottom of the flow screen.