Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to convert text to binary code in Node.js

1 Answer

0 votes
function text2bin(txt) {
    let bin = '';
    
    for (let i = 0; i < txt.length; i++) {
        let binary = txt[i].charCodeAt(0).toString(2);
        
        bin += binary.padStart(8, '0') + ' ';
    }
    
    return bin;
}

console.log(text2bin('node.js Programming'));



/*
run:

01101110 01101111 01100100 01100101 00101110 01101010 01110011 00100000 01010000 01110010 01101111 01100111 01110010 01100001 01101101 01101101 01101001 01101110 01100111 

*/

 



answered Nov 17, 2024 by avibootz

Related questions

1 answer 83 views
1 answer 119 views
1 answer 112 views
1 answer 118 views
118 views asked Nov 25, 2023 by avibootz
1 answer 118 views
...