Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: question about shift operator Message-ID: <1354@mcgill-vision.UUCP> Date: 15 Nov 88 10:29:32 GMT References: <786@gtx.com> <192@libove.UUCP> <14414@mimsy.UUCP> Distribution: na Organization: McGill University, Montreal Lines: 39 In article <14414@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > In article <192@libove.UUCP> root@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@larry.mcrcim.mcgill.edu