lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Dec 7, 2010, at 6:49 AM, Ralph Hempel wrote:

> Roberto Ierusalimschy wrote:
>>> Yup ... the bit-shifting functions in Emacs-lisp are of the "only one
>>> function with the shift-count sign determining direction" variety, and I
>>> have to check the documentation _every_ time I use them, or when I read
>>> code using them, to see what the "main" direction is -- even though I've
>>> using them (occasionally) for probably decades...
>> It shifts to the left for positive countings, does it not? It is not
>> dificult to figure out, although I have never used Emacs-lisp. If you
>> remember that shifting is basically a multiplication by a power of 2,
>> it becomes quite intuitive that 1 shifts to the left and -1 shifts to
>> the right.
> 
> That's how my mental model of shifting works too :-)
> 
> Ralph
> 

I suppose it varies with what you grew up with.  The first computer I did
assembly language programming for, the "shift" instruction shifted to the
right, and there were also "left shift" instruction to go the other way.
Also variations for circular shift and arithmetic (sign filled) left
shifts.  Oh, and 1's complement arithmetic, too..
http://www.fourmilab.ch/documents/univac/instructions.html

So shifts on the Univac computers where really divides and left shifts
multiplies.  Someone will always leap to the wrong conclusion absent
some explicit indication.

Louis Mamakos