0

I need to shorten a long string with a variable length and "decode" it back later on. The string will be built up like this 0011010011 ........ etc.

My problem right now is that the string will be over a thousand characters long which is far far too long to easily copy and paste around.

Any ideas on how to do this?

read more

Community
  • 1
  • 1
  • Do you mean that the string only has the characters 0 and 1? – Rose Kunkel Jun 27 '16 at 14:50
  • 3
    _encrypting_ is not the same as _encoding_. In this case I think you meant _encoding_. – Patrick Roberts Jun 27 '16 at 14:50
  • Also, does the string have a length that is a multiple of 8? If so, you could parse each 8 bytes as a binary integer, and store it in a Uint8Array. That would yield a compression of 8 to 1. – Patrick Roberts Jun 27 '16 at 14:52
  • Another way to go is to look into using some form of [Run-length encoding](https://en.wikipedia.org/wiki/Run-length_encoding) if you expect the string to have long runs of 1s or 0s. – Patrick Roberts Jun 27 '16 at 14:54

1 Answers1

-1

Javascript doesn't support binary data by default. I would either use an exisiting package such as binstring or write your own encoding function

Sam Anderson
  • 301
  • 2
  • 8