home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!decwrl!netcomsv!aim.com!rec
- From: rec@aim.com (Bob Cousins)
- Subject: Re: Integers implementation
- Message-ID: <1992Nov9.174528.13869@aim.com>
- Sender: news@aim.com
- Nntp-Posting-Host: lightning
- Organization: /usr/lib/news/organization
- References: <1992Nov6.144502.17520@osf.org> <MEISSNER.92Nov6161926@tiktok.osf.org>
- Date: Mon, 9 Nov 1992 17:45:28 GMT
- Lines: 78
-
- In article <MEISSNER.92Nov6161926@tiktok.osf.org> meissner@osf.org (Michael Meissner) writes:
- >In article <1992Nov6.144502.17520@osf.org> fabre@gr.osf.org (Christian
- >Fabre) writes:
- >
- >| Most of today architecture use 2's complement scheme to represent
- >| signed integers. About other possibilities, like 1's complement,
- >| I have the following questions:
- >
- >| - What are their drawbacks ?
- >1's complement and signed magnitude have -0 which plays havoc with
- >things like bit masks. Also, in 1's comp, addition is done via a
- >subtractor.
- > ...
- >| - Are they likely to pop-up in future processor design ?
-
- Actually, 2's compliment is more rightly referred to as "radix's complement"
- and 1's compliment is more rightly referred to as "radix-1's compliment" since
- the "tricks" of 1's and 2's complement arithmetic work with any radix. When I
- used to have to teach this stuff to college kids, I would always start of
- using decimal numbers (which the kids were more comfortable with).
-
- The recipe is simple:
- given C = A - B
- desired C = A + D
- where D is trivially derived from B
-
- Radix's Complement:
- for each digit in B, subtract it from (RADIX -1) and place it into
- the corresponding place in D.
- D = D + 1; (Ignore this step for Radix-1's complement)
- Perform the addition and ignore the carry.
-
- Negative values are those which are more than half the distance through
- the values. For base 10, if the left most digit is >= 5, the result is
- negative.
-
- Example:
-
- (10's complement)
- 98765 98765
- -12345 ==> 87655 (subtract each digit from 9, then add 1 to the total)
- ------ ------
- 86420 186420 (Ignore carry)
-
- Note that this is a "negative number minus a positive number." The 9's complement
- result is off by one due to the dual representation of 0. This is inherent in all
- Radix-1 implementations.
-
- Another example:
-
- 4567 4567
- -4384 ==> 5616
- ----- -----
- 0183 10183 (Ignore carry)
-
- Last example: (Above modified to have negative result)
-
- 4567 4567
- -4684 ==> 5316
- ----- -----
- -117 9883 (Ignore non-existant carry)
-
- Convert to positive value:
-
- 9999
- 9883
- ---- (Subtract each digit from 'radix -1')
- 0116
- 1 (add 1)
- ----
- 0117 (The result)
-
- Sorry to take up such bandwidth, but with the discussion of BCD and integer
- implementation on here recently, it appeared that some of the very basics
- --
- ________________________________________________________________________________
- Robert Cousins rec@aim.com (408)748-8649x212
- Aim Technology Speaking for myself alone.
-