Skip to content

Commit

Permalink
Merge pull request #6180 from BRivasTorres/main
Browse files Browse the repository at this point in the history
Reto #14 - JavaScript"
  • Loading branch information
kontroldev authored Jan 1, 2024
2 parents 6b63ff6 + 613a648 commit 90c6868
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const convertHexa = (n) => {
let res = "";
const hexaNums = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"A",
"B",
"C",
"D",
"E",
"F",
];

while (n > 0) {
let rem = n % 16;
n = Math.floor(n / 16);
res = hexaNums[rem] + res;
}

return res;
};

console.log(convertHexa(1820));
console.log(convertHexa(1970));
console.log(convertHexa(1976));
console.log(convertHexa(850));

const convertOctal = (n) => {
let res = ""
while(n > 0) {
let rem = n % 8
n = Math.floor(n/8)
res = `${rem}${res}`;
}
return res
}

console.log(convertOctal(8650))
console.log(convertOctal(1800))

0 comments on commit 90c6868

Please sign in to comment.