From: Judson Lester Date: 2008-01-26T07:03:12+09:00 Subject: Re: Circular shift On Jan 25, 2008 1:47 PM, Mental Guy wrote: > Since you showed interest, though, I'll continue with what I would > have eventually gotten to: if the register width is a power of two, > you can do some additional tricks. Let's just say I share your love for binary arithmetic. But, hey, I'm more than happy to play straight man for a good punchline. > Now, if we decide to hard-code a specific register width, we > can simplify things pretty dramatically (let's pick 8, which > is 2 ** 3): > Say, that almost sounds like a use case for a class. Something like class Register < Integer def initialize(width, value); ... end end (or even def Register(width) klass = class.new(Register) #metaprogrammy stuff to define klass::width end) But that would be drifting from the topic. > --- > > [1] Be careful when porting code to other languages; they may differ > in their treatment of negative numbers with the modulo operator, and > in C its behavior is platform-dependent. Ruby's way is the best way > for modular arithmetic though. Yeah, no kidding. C (and many related languages) also fix the width of numeric types and have built-in (<<<) circular shifts. Judson -- Your subnet is currently 169.254.0.0/16. You are likely to be eaten by a grue.