Convert HEX) to Decimal

Need to covert EnergyToday (HEX) to Decimal. What is the best way to do this?

<response>
<EnergyToday>00BB</EnergyToday>
<EnergyYesterday>02EC</EnergyYesterday>
<EnergyLifetime>00283FDE</EnergyLifetime>
<HeaterInstallEnergy>00000000</HeaterInstallEnergy>
<HoursExportedToday>424</HoursExportedToday>
<HoursExportedYesterday>489</HoursExportedYesterday>
<HoursExportedLifetime>00118017</HoursExportedLifetime>
<DaysProducing>06CC</DaysProducing>
<HeaterInstalled>0000</HeaterInstalled>
<InsolationToday>0000</InsolationToday>
<InsolationYesterday>0000</InsolationYesterday>
<MeterToday>00000000</MeterToday>
<MeterYesterday>0000</MeterYesterday>
<MeterLifetime>00000000</MeterLifetime>
<HeaterToday>0000</HeaterToday>
<HeaterYesterday>0000</HeaterYesterday>
<HeaterLifetime>00000000</HeaterLifetime>
<ExportToday>0000</ExportToday>
<ExportYesterday>0000</ExportYesterday>
<ExportLifetime>00000000</ExportLifetime>
<ImportToday>0000</ImportToday>
<ImportYesterday>0000</ImportYesterday>
<ImportLifetime>00000000</ImportLifetime>
</response>

Pass the XML through an XML node to create a JS object then you could access the object properties in a function node & convert their values to numbers using parseInt.

Thanks thats the part I can get right, need to add the fn node after the change node but the code is killing me.

What's your function code?

msg.payload = parseInt("0x"+msg.payload);

this works but changes Preformatted text00BB to 187 where I want 1.87

Can add the calulator node and divide by 100 but there must be a better way?

00bb is 187

However, you want a different value, divide by 100 or use the scale node.

msg.payload = parseInt("0x"+msg.payload) / 10.0;
return msg;

However from my original suggestion above, I would have done this....

DATA > XML NODE (convert data to js object) > FUNCTION NODE (convert all values in one place)

Thanks will revise as per your advice....

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.