jeudi 2 avril 2015

How to efficiently store arbitrary binary data in character string?

I'm participating in a small competition with a message passing capability. I'm given a maximum 64 character javascript string in which I can store anything.


My understanding is that Javascript srings can store unicode characters, and that the maximum a UTF-16 encoding can store is U+10FFFF, or 21 bits. If I simplify to 20 bits (2.5 bytes) per character, I have 160 bytes in a 64 character javascript UTF-8 string.



  • Is this correct?

  • Is this encoding the maximum reliable (ie works on chrome, ie, firefox, popular mobile, etc) encoding per character in a javascript string1?

  • I don't mind doing the work, but I'm no javascript programmer - what functions should I look at to safely convert my 160 byte array into a 64 character string, and vice versa?

  • What pitfalls should I be aware of?


1This is a self contained program, while the program will pass these messages around within itself, it will not send data to other systems/servers/clients and expect them to understand.


Aucun commentaire:

Enregistrer un commentaire