Skip to content

Instantly share code, notes, and snippets.

@zkingboos
Last active August 16, 2021 12:41
Show Gist options
  • Save zkingboos/4fffbd779f94c1d90df7b7517c0c2b9b to your computer and use it in GitHub Desktop.
Save zkingboos/4fffbd779f94c1d90df7b7517c0c2b9b to your computer and use it in GitHub Desktop.
const value = prompt("Input required")
const base = prompt("Base required")
const adapters = { 16: { "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15 } }
const formula = value
.split("")
.reverse()
.map((item, index) => `${(adapters[base] || {})[item] || item} * ${base} ^ ${index}`)
.reverse()
.join(" + ");
alert(formula)
Input required: FACA
Base required: 16
Output: 15 * 16 ^ 3 + 10 * 16 ^ 2 + 12 * 16 ^ 1 + 10 * 16 ^ 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment