http://qs321.pair.com?node_id=11121871


in reply to Losing Bits with Pack/Unpack

Are you trying to maximize the amount of data you can stuff into a single tweet by abusing Twitter's arbitrarily defined character limit rules?

If yes, there are schemes for that: see e.g. https://github.com/qntm/base2048

Replies are listed 'Best First'.
Re^2: Losing Bits with Pack/Unpack
by o0lit3 (Friar) on Sep 17, 2020 at 14:34 UTC
    Yeah, this is the idea. I see this javascript solution uses a lookup array and is using bitwise operations to construct an index to lookup in the array... Seems like this could be rewritten in perl with similar bitwise ops, but there is no "simple" solution using only pack and unpack based on the fact that those methods are byte aligned. Thanks for the help!
      I doubt there are any simple solutions with just pack and unpack. Most of the complexity of the base2048 implementation I've linked comes from paying attention to Twitter's rules about what it considers a "text" or "CJK" or "sendable" character. Perl's comprehensive Unicode support (character classes in regexes etc.) might be useful, if you were to rewrite the thing in it.