Binary Converter

This might help, if I understand what you’re trying to do.

First you could start with converting a string to the binary representation of its character codes, then work backwards from the output to make sure you get the same input. Try something like this in the console:

for (c of 'banana') console.log(c, c.charCodeAt(0).toString(2).padStart(8, '0'))

That should output this:

b 01100010 
a 01100001 
n 01101110 
a 01100001 
n 01101110 
a 01100001

So, you want to take ‘011000100110000101101110’ and output ‘ban’, right?

I’d probably do something like this (test in console):

var binary = '011000100110000101101110'
binary.replace(/.{8}/g, b => String.fromCharCode(parseInt(b, 2)))

Then just wrap that guy up in a function and you should be good to go. Make sure to validate or sanitize the input first – either strip out anything that’s not a 0 or 1, then zero-pad so it has a multiple of 8 characters, or throw it out if it doesn’t fit that pattern.

This is assuming you only care about ASCII characters that fit in 8 bits, of course – characters as bytes, not characters as unicode codepoints.