How to convert text to binary code in JavaScript?

后端 未结 13 1832
囚心锁ツ
囚心锁ツ 2020-11-28 05:00

Text to Binary Code

I want JavaScript to translate text in a textarea into binary code.

For example, if a user types in "TEST

13条回答
  •  时光说笑
    2020-11-28 05:41

    This might be the simplest you can get:

    function text2Binary(string) {
        return string.split('').map(function (char) {
            return char.charCodeAt(0).toString(2);
        }).join(' ');
    }
    

提交回复
热议问题