0

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?

UTF-8 vs. Unicode

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?

Community
  • 1
  • 1
user137717
  • 2,005
  • 4
  • 25
  • 48
  • Have you read this? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt – xxbbcc Jan 05 '15 at 21:10
  • 1
    Your question is also pretty vague. Please post your code for more detail. I don't understand what you mean by _I'm getting the minimum number of bits..._ `getCharCodeAt` returns a character code in the specified string position - unless I'm missing something, this is not related to bits. – xxbbcc Jan 05 '15 at 21:13

0 Answers0