From e75049551ffe61c31530601fa1687cd5cc95903c Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 1 Aug 2023 12:57:30 +0100 Subject: [PATCH] Print memory tables in hex --- sketches/print-memory.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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