[LRUG] How would you turn a bit stream into a character stream?

James Coglan jcoglan at gmail.com
Mon Jun 11 06:25:33 PDT 2012


On 11 June 2012 14:15, Chris Parsons <chris.p at rsons.org> wrote:

> Hmm, interesting. Feels like a bug causing 13-15 to appear three times as
> often. Can we see the code?
>

The codes actually JS. Ruby would look something like this, for taking the
next chunk of the bit stream:

n = Math.ceil(Math.log(charset.size) / Math.log(2))
chunk = bits[0...n]
return chunk if chunk =~ /^0/ # definitely within range
value = chunk.to_i(2)
return (value >= size.size) ? chunk[0..-2] : chunk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120611/2bd22e2f/attachment.html>


More information about the Chat mailing list