Skip to content

Instantly share code, notes, and snippets.

@nhuxhr
Created July 20, 2021 02:01
Show Gist options
  • Save nhuxhr/f054c38dd06b5980d0331e3b449d6063 to your computer and use it in GitHub Desktop.
Save nhuxhr/f054c38dd06b5980d0331e3b449d6063 to your computer and use it in GitHub Desktop.
Convert Text to Binary
/**
* 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