DEC to HEX frame

by Tomáš

HTML

<p id="out">

</p>

JavaScript

// nemazat
let input = `
180119390
180119386
` // nemazat




function pad(n) {
  return (n.length%2 != 0 ? "0"+n : n);
}

let output = [];
output.push(`filter = ""`);

for (let x of input.split("\n")) {
	if (x.length > 0) {
  	const hexNum = pad(parseInt(x, 10).toString(16));
    let arr = [];
    for (let y of hexNum.split(/(?=(?:..)*$)/).reverse()) {
    	arr.push(`0x${y}`);
    }
		output.push(`filter = filter .. string.char(${arr.join(", ")}) -- 0x${hexNum}`);
  }
}

output.push(`filterLength = #filter/4`);
output.push(`api.wmbusFilter("populate", filter)`);


document.getElementById("out").innerHTML = output.join("<br/>");