Created
May 10, 2020 10:53
-
-
Save einnor/66afa8ce1cec6902730558c65303a104 to your computer and use it in GitHub Desktop.
Hex, Octal, Decimal, Binary Conversions
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
// To Decimal | |
const hexToDecimal = (hex) => { | |
return parseInt(hex, 16); | |
}; | |
const octalToDecimal = (octal) => { | |
return parseInt(octal, 8); | |
}; | |
const binaryToDecimal = (binary) => { | |
return parseInt(binary, 2); | |
}; | |
// To Binary | |
const decimalToBinary = (decimal) => { | |
return decimal.toString(2); | |
}; | |
const hexToBinary = (hex) => { | |
const decimal = hexToDecimal(hex); | |
return decimalToBinary(decimal); | |
}; | |
const octalToBinary = (octal) => { | |
const decimal = octalToDecimal(octal); | |
return decimalToOctal(decimal); | |
}; | |
// To Hex | |
const decimalToHex = (decimal) => { | |
return decimal.toString(16); | |
}; | |
const binaryToHex = (binary) => { | |
const decimal = binaryToDecimal(binary); | |
return decimalToHex(decimal); | |
}; | |
const octalToHex = (octal) => { | |
const decimal = octalToDecimal(octal); | |
return decimalToHex(decimal); | |
}; | |
// To Octal | |
const decimalToOctal = (decimal) => { | |
return decimal.toString(8); | |
}; | |
const binaryToOctal = (binary) => { | |
const decimal = binaryToDecimal(binary); | |
return decimalToOctal(decimal); | |
}; | |
const hexToOctal = (hex) => { | |
const decimal = hexToDecimal(hex); | |
return decimalToOctal(decimal); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment