6 examples of '8.3.9: text to binary' in JavaScript

Every line of '8.3.9: text to binary' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17function convert_text_to_binary(string) {
18 let data = new TextEncoder("utf-8").encode(string);
19 return data
20}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

24function bytesToBinary(bytes) {
25 return bytes.map(x => lpad(x.toString(2), '0', 8)).join('');
26}
44function convertToBinaryString(data) {
45 if(!data) {
46 return;
47 }
48 let binary = "";
49 const bytes = new Uint8Array(data);
50 for (var i = 0; i < bytes.byteLength; i++) {
51 binary += String.fromCharCode(bytes[i]);
52 }
53 return binary;
54}
195arrayBufferToBinary(t) {
196 let e = '';
197 const n = new Uint8Array(t),
198 r = n.byteLength;
199 for (let t = 0; t < r; t++) e += String.fromCharCode(n[t]);
200 return e;
201}
21function binaryToByte(bin) {
22 return parseInt(bin, 2);
23}
124function binl2str(bin){
125 var str = "";
126 var mask = (1 << chrsz) - 1;
127 for(var i = 0; i < bin.length * 32; i += chrsz) {
128 str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
129 }
130 return str;
131}

Related snippets