Created
July 20, 2021 02:01
-
-
Save nhuxhr/f054c38dd06b5980d0331e3b449d6063 to your computer and use it in GitHub Desktop.
Convert Text to Binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert Text to Binary | |
* @author JSX Clan <jsxclan.dev@gmail.com> | |
*/ | |
const text2Binary = (str = '') => { | |
return str.split('').map((char) => { | |
return char.charCodeAt(0).toString(2); | |
}).join(' '); | |
} | |
console.log(text2Binary('I love JavaScript')); | |
// Output: 1001001 100000 1101100 1101111 1110110 1100101 100000 1001010 1100001 1110110 1100001 1010011 1100011 1110010 1101001 1110000 1110100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment