Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site turtlevax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!decwrl!turtlevax!ken From: ken@turtlevax.UUCP (Ken Turkowski) Newsgroups: net.arch Subject: Re: Right shift vs. divide Message-ID: <1019@turtlevax.UUCP> Date: Fri, 10-Jan-86 17:39:52 EST Article-I.D.: turtleva.1019 Posted: Fri Jan 10 17:39:52 1986 Date-Received: Mon, 13-Jan-86 08:03:11 EST References: <3000002@convexs> <4782@alice.UUCP> Reply-To: ken@turtlevax.UUCP (Ken Turkowski) Organization: CIMLINC, Inc. @ Menlo Park, CA Lines: 24 In article <4782@alice.UUCP> ark@alice.UucP (Andrew Koenig) writes: > -2147483648 is 80000000 hex. Negate it and you > get integer overflow. If this is masked, most machines > will give you 80000000 hex back. > > Shift 80000000 right 1 bit, giving C0000000. > > Negate this again, giving 40000000. > >Thus, the sign gets lost. Wrongo. After you negate the original negative number, it becomes an unsigned number without overflow. When you shift, you use an unsigned shift. Then, Shift 80000000 right by 1 bit, giving 40000000. Negate this again, giving, C0000000 (-1073741824) This is the correct result. -- Ken Turkowski @ CIMLINC, Menlo Park, CA UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken ARPA: turtlevax!ken@DECWRL.DEC.COM