<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 11 Jun 2012, at 14:25, James Coglan wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote"><div>n = Math.ceil(Math.log(charset.size) / Math.log(2))</div><div>chunk = bits[0...n]</div><div>return chunk if chunk =~ /^0/ # definitely within range</div><div>value = chunk.to_i(2)</div><div>return (value >= size.size) ? chunk[0..-2] : chunk</div>
</div></blockquote><br></div><div>Hmm: at first glance it feels like you're wrapping the three indexes greater than your range into indexes for 13-15 by stripping off the last two bits from the chunk. How about just throwing the bits away if you're not in range? Depends how significant the data is, and whether you need to crunch x bits into exactly x/5 characters or not.</div><div><br></div><div>Chris</div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">--<br>Chris Parsons<br><a href="mailto:chris.p@rsons.org">chris.p@rsons.org</a><br>http://twitter.com/chrismdp<br>http://pa.rsons.org<br><br><br><br></span>
</div>
<br></body></html>