I have been using charCodeAt()
to break strings into unicode values and then convert them to binary so I can change the encoding. I've read more about character encoding in these posts
If UTF-8 is an 8-bit encoding, why does it need 1-4 bytes?
and on wikipedia. All the character I am processing will be in the ASCII subset of unicode so I am expecting one byte when I convert the codes to binary with Javascript's toString()
(2) method. However, I get the minimum number of bits possible to represent the code when I convert. Can someone please explain more about what is happening here. I'm confused as to whether javascript is truncating the binary string or whether it has to do with how the characters are encoded. Is there a way to get the full byte back from javascript without having to extend it myself?