home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / arch / 10559 < prev    next >
Encoding:
Text File  |  1992-11-09  |  3.1 KB  |  91 lines

  1. Newsgroups: comp.arch
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!decwrl!netcomsv!aim.com!rec
  3. From: rec@aim.com (Bob Cousins)
  4. Subject: Re: Integers implementation
  5. Message-ID: <1992Nov9.174528.13869@aim.com>
  6. Sender: news@aim.com
  7. Nntp-Posting-Host: lightning
  8. Organization: /usr/lib/news/organization
  9. References: <1992Nov6.144502.17520@osf.org> <MEISSNER.92Nov6161926@tiktok.osf.org>
  10. Date: Mon, 9 Nov 1992 17:45:28 GMT
  11. Lines: 78
  12.  
  13. In article <MEISSNER.92Nov6161926@tiktok.osf.org> meissner@osf.org (Michael Meissner) writes:
  14. >In article <1992Nov6.144502.17520@osf.org> fabre@gr.osf.org (Christian
  15. >Fabre) writes:
  16. >
  17. >| Most of today architecture use 2's complement scheme to represent
  18. >| signed integers. About other possibilities, like 1's complement,
  19. >| I have the following questions:
  20. >
  21. >|  - What are their drawbacks ?
  22. >1's complement and signed magnitude have -0 which plays havoc with
  23. >things like bit masks.  Also, in 1's comp, addition is done via a
  24. >subtractor.
  25. >    ...
  26. >|  - Are they likely to pop-up in future processor design ?
  27.  
  28. Actually, 2's compliment is more rightly referred to as "radix's complement"
  29. and 1's compliment is more rightly referred to as "radix-1's compliment" since
  30. the "tricks" of 1's and 2's complement arithmetic work with any radix. When I
  31. used to have to teach this stuff to college kids, I would always start of
  32. using decimal numbers (which the kids were more comfortable with).
  33.  
  34. The recipe is simple:
  35.     given C = A - B
  36.     desired C = A + D
  37.     where D is trivially derived from B
  38.  
  39. Radix's Complement:
  40.     for each digit in B, subtract it from (RADIX -1) and place it into
  41.     the corresponding place in D.
  42.     D = D + 1;  (Ignore this step for Radix-1's complement)
  43.     Perform the addition and ignore the carry.
  44.  
  45.     Negative values are those which are more than half the distance through
  46.     the values. For base 10, if the left most digit is >= 5, the result is
  47.     negative.
  48.  
  49. Example:
  50.  
  51.                (10's complement)
  52.     98765      98765
  53.        -12345  ==> 87655 (subtract each digit from 9, then add 1 to the total)
  54.        ------     ------
  55.     86420     186420 (Ignore carry)
  56.  
  57. Note that this is a "negative number minus a positive number." The 9's complement
  58. result is off by one due to the dual representation of 0. This is inherent in all
  59. Radix-1 implementations.
  60.  
  61. Another example:
  62.  
  63.     4567       4567
  64.        -4384  ==>  5616
  65.        -----      -----
  66.         0183      10183 (Ignore carry)
  67.  
  68. Last example: (Above modified to have negative result)
  69.  
  70.     4567       4567
  71.        -4684  ==>  5316
  72.        -----      -----
  73.         -117       9883 (Ignore non-existant carry)
  74.  
  75.     Convert to positive value:
  76.  
  77.     9999 
  78.     9883
  79.     ----  (Subtract each digit from 'radix -1')
  80.     0116
  81.        1  (add 1)
  82.     ----
  83.     0117  (The result)
  84.  
  85. Sorry to take up such bandwidth, but with the discussion of BCD and integer 
  86. implementation on here recently, it appeared that some of the very basics
  87. -- 
  88. ________________________________________________________________________________
  89. Robert Cousins                    rec@aim.com                  (408)748-8649x212
  90. Aim Technology                                        Speaking for myself alone.
  91.