How to convert ASCII values to 8-bit binary in javascript?

How to convert ASCII values to 8-bit binary in javascript?
For example, if the ASCII value is 104, then it’s 8 bit binary should be 01101000

Hi @abdulrahmanmhdanas, you can get the binary (or any other) representation of a number by passing the radix to the toString() method:

const number = 104
console.log(number.toString(2)) // 1101000
1 Like

You could also pad the binary with leading zeros, if necessary.

console.log(number.toString(2).padStart(8,'0')) // 01101000
3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.