Skip to content

Instantly share code, notes, and snippets.

@codewithpom
Created November 19, 2021 09:06
Show Gist options
  • Save codewithpom/ba1385c413147cd49f36197d57a42e9f to your computer and use it in GitHub Desktop.
Save codewithpom/ba1385c413147cd49f36197d57a42e9f to your computer and use it in GitHub Desktop.
Convert a character to binary using js.
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