Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 16:20
Show Gist options
  • Save parzibyte/c65ea4fea9f804510d50add4ee58d787 to your computer and use it in GitHub Desktop.
Save parzibyte/c65ea4fea9f804510d50add4ee58d787 to your computer and use it in GitHub Desktop.
/**
* Desde decimal a otras bases
* parzibyte.me/blog
* @author parzibyte
*/
let decimal = 255; // Este número lo iremos convirtiendo a todas las bases
// Decimal a binario
let decimalEnBinario = decimal.toString(2); // A la base 2
console.log("El número decimal %s en binario es %s", decimal, decimalEnBinario);
// Decimal a octal
let decimalEnOctal = decimal.toString(8); // A la base 8
console.log("El número decimal %s en octal es %s", decimal, decimalEnOctal);
// Decimal a hexadecimal
let decimalEnHexadecimal = decimal.toString(16); // A la base 16
console.log("El número decimal %s en hexadecimal es %s", decimal, decimalEnHexadecimal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment