Link to home
Start Free TrialLog in
Avatar of Steve Tinsley
Steve TinsleyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Convert number to hexadecimal using Node javascript

I am trying to control a bit of AV equipment using the TCP control API. Here is a screenshot of the command I am trying to build.
User generated image
This is currently my code:
con = 3017; //0xC9 0x0B
cpu = 1012; //0xF4 0x03
cmd = Buffer.from([
     0x1B,
     0x5B,
     0x49,
     0x09,
     0x00,
     parseInt(con || 0, 10),
     parseInt(cpu || 0, 10)
]);

Open in new window


My output is:
1B 5B 49 09 00 C9 F4

But I want to get this:
1B 5B 49 09 00 C9 0B F4 03

I think it's because the CON & CPU are 2 bytes, but I don't know how to fix it.

Please can someone help
ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial