Re: [SLUG] Numeric Storage Format

From: Ian C. Blenke (icblenke@nks.net)
Date: Fri Dec 29 2006 - 02:27:07 EST


Eben King wrote:
>> nstr = "57";
>> ch = nstr[0] - '0';
>> number = 10 * ch + nstr[1] - '0';
>
> So in memory it'd be '5' '7' NUL = 0x35 0x37 0x00, right?

The source ASCII string, nstr, is "57", which would be 0x35 0x37 0x00 as
a null terminated string, correct.

>> Okay, now after all the explanation, what is this storage format
>> *called*? It's not BCD, and it's not packed decimal. I'd like to know
>> what it's called, so I can look up references on it.
>
> I'd call it "stored as an ASCII string" m'self, but ICBW.

I think he is saying that he is converting from an ASCII string to this
format. The format is a binary representation of the number, by
subtracting the value of an ASCII "0", ie:

    0x35 0x37 0x00

becomes

    0x05 0x07
or
    number=10 * 0x05 + 0x07
so that
    number=57

ie, an integer representation of the string.

The question boils down to how to handle negative numbers: one's
complement or two's complement. I'll wager that it is the latter.

- Ian



-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:15:25 EDT