Noah Easterly wrote:
> To use little endian order use 'v' and 'V', respectively.

Ah, thanks.

> You're ignoring a bunch of edge cases here.
> 0 and 1, for example.
[...]
> What you should actually do, instead of taking the ceiling, is round
> down and add one.

Thanks for pointing that out.


> You're also ignoring negative integers.

On purpose, actually. I happen to know in my domain that it would be an
error to hit that case. I prefer to keep my code lean and leave out
various validity checks that also kill the program (albeit in a
slightly cleaner way).


> # The natural log of 256 (for base-256 logarithms)
> Math::LOG256 = Math.log( 256 )

Ah, tricky! I'm unused to thinking of crazy-high bases. That's a nice
shortcut, thanks.


>   def self.from_bytestring( str )
>     str.reverse.split(//).inject(0) do |val, char|
>       (val << 8) | char[0]
>     end

No solution is complete without an inject. ;)
I wonder (haven't tested yet): is splitting on "" any faster than
splitting on //?
Introducing a string.reverse also feels to me like it would slow things
down. Will need to run some benchmarks.


Thanks for the ideas and code!