Article View: comp.arch
Article #21920Re: Integer Multiply/Divide
From: Preston Briggs
Date: Wed, 03 Jan 1990 05:23
Date: Wed, 03 Jan 1990 05:23
22 lines
1207 bytes
1207 bytes
In article <9193@cbmvax.commodore.com> jesup@cbmvax.commodore.com (Randell Jesup) writes:
>In article <4057@brazos.Rice.edu> preston@titan.rice.edu (Preston Briggs) writes:
>>Division is slightly more complex, due to sign handling.
>>For most languages, it isn't safe to replace a divide by 2^N
>>with a shift right (doesn't work for negative numbers).
> Easy solution: x/2^n = (x >> n) + (x & 1 & (bit 31 of x)). Of course,
>the >> operation must be "arithmetic" and not "logical"
But what about -6/4 ?
6 = 0...0110
-6 = 1...1010
x>>2 = 1...1110 + (1...1010 & 1 & (x >> 31))
= 1...1110 + 0
= 1...1110
= -2
On the other hand, perhaps I've misinterpreted your intent.
Preston Briggs
Technical Details
Message-ID:
<4081@brazos.Rice.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!rice!titan!prestonReferences:
<84768@linus.UUCP> <4057@brazos.Rice.edu> <9193@cbmvax.commodore.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!rice!titan!preston From: preston@titan.rice.edu (Preston Briggs) Newsgroups: comp.arch Subject: Re: Integer Multiply/Divide Message-ID: <4081@brazos.Rice.edu> Date: 3 Jan 90 05:23:21 GMT References: <84768@linus.UUCP> <4057@brazos.Rice.edu> <9193@cbmvax.commodore.com> Sender: root@rice.edu Reply-To: preston@titan.rice.edu (Preston Briggs) Organization: Rice University, Houston Lines: 22