convert base10 to base2 and back
by trentHarlem
HTML
<p>
In a positional numeral system, the radix or base is the number of unique digits, including the digit zero, used to represent numbers. <br>
<small>https://en.wikipedia.org/wiki/Radix</small>
</p>
JavaScript
// integer
const num = 69
// convert int to string type AND select the radix or base output
const bin = num.toString(2) // "1000101"
// converts the integer 69 from base 10 to String(base 2)
console.log(bin)
const myBaseTwo = +bin
// can use parseInt to convert back to base10
const baseTen = parseInt(myBaseTwo, 2)
// parseInt outputs base10 by default. we pass in (1)the string(current representation of the number) and (2) the base of the current representation)
console.log(baseTen)