question about shift operator

der Mouse mouse at mcgill-vision.UUCP
Tue Nov 15 20:29:32 AEST 1988


In article <14414 at mimsy.UUCP>, chris at mimsy.UUCP (Chris Torek) writes:
> In article <192 at libove.UUCP> root at libove.UUCP (Jay M. Libove) writes:
>> Looking at the above, I read it to be "shift an n-bit integer n bits
>> left" ... Now, why is there any question as to the result?
> Because different machines implement shift-left differently.
>> (One machine test ....
> Try a better test.
> [sample program, with shift count not known at compile time]

> On the VAX, the result of shifting by the (not known to be constant)
> value 32 is the same as the result of shifting by zero, because the
> VAX looks only at the 5 lowest order bits of the shift count.

What sort of VAX is this you're talking about, Chris?  The Gray Book,
revision 6.1, dated 20 May 1982, says that the ASHL shift count is a
signed byte.  Then, under "Notes:", it says

    2. If cnt GTR 32 (ASHL) or cnt GTR 64 (ASHQ) the destination
       operand is replaced by 0.

    3. If cnt LEQ -31 (ASHL) or cnt LEQ -63 (ASHQ) all the bits of the
       destintation operand are copies of the sign bit of the source
       operand.

I assume note 2 is supposed to read GEQ instead of GTR, or 31 and 63
instead of 32 and 64.

I tried this and (a) the compiler used an ashl to do the shift and (b)
it worked the way the book says: 1<<32==0.  Machines were a 750 and a
MicroVAX-II.

If a right shift is simply a negative left shift, and it uses only the
low five bits, could you explain the difference between i<<30 and i>>2
to me, please?

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list