Ian C. Blenke wrote:
> 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
>
No no no. BCD stores one digit per nibble. The "digits" here aren't
stored as digits. Each byte contains a binary number from 0-99. The
example above, expressed as hexadecimal, would be stored as 0x39.
Forget signs. The library uses a C structure to store numbers. The
exponent and sign are stored as separate fields. The significant digits
are what we're talking about here.
FWIW, the link to the library in question is:
http://www.tc.umn.edu/~ringx004/mapm-main.html
I'm having to do price lists and payroll in PHP, and the math
inaccuracies are killing me. I haven't been able to find any *good*
arbitrary precision library for PHP, so I'm working or porting or
adapting this C library to PHP.
So anyway, what do you call this storage format?
Paul
-- Paul M. Foster ----------------------------------------------------------------------- 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:27 EDT