www.ShoppingPodder.com

Leading Computer Shopping,
News and information


Part of the Identityscape.com network...

getxfactor.com jmoodmusic.com smartbusinesschoices.com mintdepot.com lowfaresalways.com evangelicalview.com shoppingpodder.com soproudlywehail.com webnews.ws currenthumor.com

 

 

ZONNC: Hiding the Sign of a Decimal Number
   Shopping Podder - the Best of Computer Postings! Forum Index -> Computer Architecture - Arithmetic  
View previous topic :: View next topic  
Author Message
Quadibloc
Guest






PostPosted: Tue Jan 22, 2008 12:53 am    Post subject: ZONNC: Hiding the Sign of a Decimal Number Reply with quote

Generally, if a decimal number is represented by packed BCD, one of
the digits is used to represent the sign.

This is, of course, an unnecessary inefficiency. If packed decimal is
aligned on byte boundaries, so that the number of digits must be even,
with a minimum-length number of 256 digits, the inefficiency of
packed decimal, with 256 codes standing for 100 values, already leaves
enough excess room for the sign.

But how to encode the sign?

One could begin the byte with a sign bit, and then have the remaining
7 bits encode a value from 0 to 99 in binary.

Or the remaining 7 bits could encode the two digits using Chen-Ho
coding.

I had thought that if one gave up having the sign bit in a fixed
location, one could get a coding that was even simpler, although, come
to think of it, probably my coding, in its second improved version, is
not all that different from two-digit Chen-Ho coding.

ZONNC is described on the page

http://www.quadibloc.com/arch/ar0201.htm

and involves having the first digit of the number code for some
negative and positive values, as shown here for the improved version:

+0n -> 0n
+1n -> 1n
+2n -> 2n
+3n -> 3n
+4n -> 4n
+5n -> 5n
+6n -> 6n
+7n -> 7n
-0n -> 8n
-1n -> 9n
-2n -> An
-3n -> Bn
-4n -> Cn
-5n -> Dn
-6n -> En
-7n -> Fn

and the remaining values are encoded by making the second digit of the
number one of the unused values:

+8n -> nC
+9n -> nD
-8n -> nE
-9n -> nF

The basic principle is indeed much like Chen-Ho encoding, the only
advantage is that when the sign is folded in, things happen at the
four-bit digit boundary, improving readability. The original version
would involve more logic circuits, but has the advantage that +8n and
+9n encode to 8n and 9n, so that all numbers with an unused BCD value
are negative.

John Savard
Back to top
Terje Mathisen
Guest






PostPosted: Tue Jan 22, 2008 1:46 pm    Post subject: Re: ZONNC: Hiding the Sign of a Decimal Number Reply with quote

Quadibloc wrote:
Quote:
Generally, if a decimal number is represented by packed BCD, one of
the digits is used to represent the sign.

This is, of course, an unnecessary inefficiency. If packed decimal is
aligned on byte boundaries, so that the number of digits must be even,
with a minimum-length number of 256 digits, the inefficiency of
packed decimal, with 256 codes standing for 100 values, already leaves
enough excess room for the sign.

This is _not_ how you store BCD, and I know that you know that. :-(

You store them modulo some power of 10, like 1e9 for a 32-bit binary
cpu, or 1e3 (1000) in the standard for decimal fp.

Using 10 bits for each group of 3 digits still allows very efficient
conversion to/from a 12-bit pure BCD representation (discrete logic
and/or lookup tables).

There is a standard packing method for decimal FP that allows conversion
with discrete logic, making it feasible to handle all groups in
parallel. Try to figure it out, it isn't too hard to rediscover:

The parity/bottom bit of each digit can always be stored as-is, this
leaves 7 bits to encode 3 modulo-5 values, which is 128 patterns for 125
possible values.

The problem is of course how to encode the 8 possible combinations of
the digit 4 occurring in any position. You have one free bit to do so. :-)

Terje
--
- <Terje.Mathisen@hda.hydro.com>
"almost all programming can be viewed as an exercise in caching"
Back to top
Quadibloc
Guest






PostPosted: Tue Jan 22, 2008 3:46 pm    Post subject: Re: ZONNC: Hiding the Sign of a Decimal Number Reply with quote

On Jan 22, 12:46 am, Terje Mathisen <terje.mathi...@hda.hydro.com>
wrote:

Quote:
This is _not_ how you store BCD, and I know that you know that. :-(

You store them modulo some power of 10, like 1e9 for a 32-bit binary
cpu, or 1e3 (1000) in the standard for decimal fp.

My novel scheme isn't how BCD is stored at present, true, but that
doesn't seem to be what you mean here.

Storing decimal numbers in binary form certainly is possible, but that
isn't how decimal values are stored _on computers that can perform
decimal arithmetic directly_ although it's certainly true that
computers that perform binary arithmetic still print results and read
data in binary form.

The form I was using as an example of how decimal is stored is the one
used on System/360; packed decimal values were indeed stored at 4 bits
to the digit, with one digit containing a code indicating the sign.

John Savard
Back to top
Display posts from previous:   
   Shopping Podder - the Best of Computer Postings! Forum Index -> Computer Architecture - Arithmetic  
Page 1 of 1
All times are GMT

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum