Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 16:21
Show Gist options
  • Save parzibyte/c755146561153ce158ad0faa0cb9fec5 to your computer and use it in GitHub Desktop.
Save parzibyte/c755146561153ce158ad0faa0cb9fec5 to your computer and use it in GitHub Desktop.
/**
* Desde otras bases a decimal
* parzibyte.me/blog
* @author parzibyte
*/
// Binario a decimal
let binario = "1100"; // 12
let binarioEnDecimal = parseInt(binario, 2); // La base es 2
console.log("El número binario %s en decimal es %s", binario, binarioEnDecimal);
// Octal a decimal
let octal = "60"; // 48
let octalEnDecimal = parseInt(octal, 8); // La base es 8
console.log("El número octal %s en decimal es %s", octal, octalEnDecimal);
// Hexadecimal a decimal
let hexadecimal = "FF"; // 255
let hexadecimalEnDecimal = parseInt(hexadecimal, 16); // La base es 16
console.log("El número hexadecimal %s en decimal es %s", hexadecimal, hexadecimalEnDecimal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment