From 31d5467ada845dca245a6c49e0f9330d8a6f0dd5 Mon Sep 17 00:00:00 2001 From: Alex Brown Date: Sat, 20 Oct 2018 15:35:49 -0500 Subject: [PATCH] added DecimalToHex --- Conversions/DecimalToHex.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Conversions/DecimalToHex.js diff --git a/Conversions/DecimalToHex.js b/Conversions/DecimalToHex.js new file mode 100644 index 000000000..f95649b2a --- /dev/null +++ b/Conversions/DecimalToHex.js @@ -0,0 +1,19 @@ +function intToHex(num){ + switch(num){ + case 10: return "A"; + case 11: return "B"; + case 12: return "C"; + case 13: return "D"; + case 14: return "E"; + case 15: return "F"; + } + return num; +} +function decimalToHex(num){ + let hex_out = []; + while(num > 15) { + hex_out.push(intToHex(num%16)); + num = Math.floor(num / 16); + } + return hex_out.join(""); +}