Created
November 19, 2021 09:06
-
-
Save codewithpom/ba1385c413147cd49f36197d57a42e9f to your computer and use it in GitHub Desktop.
Convert a character to binary using js.
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
function convert_char_to_binary(char){ | |
const code = char.charCodeAt(0); // convert the char to ASCII (UTF-16) | |
return code.toString(2); // convert ASCII integer to binary | |
} | |
const binary = convert_char_to_binary("a") | |
console.log(binary) // logs '1100001' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment