diff --git a/sketches/print-memory.js b/sketches/print-memory.js index 1e370cc..3533fc7 100644 --- a/sketches/print-memory.js +++ b/sketches/print-memory.js @@ -3,13 +3,12 @@ exports.printTable = (x) => { console.log(`│ addr │ op │ arg │`); console.log(`├────────┼────────┼────────┤`); for (let i = 0; i < x.length; i += 2) { - console.log(`│ ${leftPadNum(i)} │ ${leftPadNum(x[i])} │ ${leftPadNum(x[i+1])} │`); + console.log(`│ ${num2hex(i)} │ ${num2hex(x[i])} │ ${num2hex(x[i+1])} │`); if (((i + 2) % 8) === 0) { console.log(`│ │ │ │`); } } console.log(`└────────┴────────┴────────┘`); - function leftPadNum(n) { - return n.toString().padStart(2, "0") - } -} \ No newline at end of file +} + +const num2hex = (num) => num.toString(16).toUpperCase().padStart(2, "0"); \ No newline at end of file