Files
JavaScript/Maths/BinaryConvert.js
Arwy Syahputra Siregar eab57b880a add binary convert (#521)
* add  binary convert
2020-10-31 20:22:50 +05:30

11 lines
397 B
JavaScript

const BinaryConvert = (number) => {
const result = []
let i
for (i = number; i > 0; i = parseInt(i / 2)) {
result.push(i % 2) // push the value (remainder)to array
} return Number(result.reverse().join(''))
// reverse index of array as string ,join and change the type of value to become Number
}
// call function and value as parameter to passing the value
export { BinaryConvert }