-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6180 from BRivasTorres/main
Reto #14 - JavaScript"
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/javascript/BRivasTorres.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |