[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Base conversion within Base
From: |
Greg Wooledge |
Subject: |
Re: Base conversion within Base |
Date: |
Wed, 17 Sep 2014 09:04:43 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Wed, Sep 17, 2014 at 08:46:28AM -0400, IT1 Stuart Blake Tener, USNR wrote:
> In as much as bc only tells you which position in the string
> "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" it corresponds too.
>
> Useless and incomplete without a script to complete it! Thus, a bug
> worthy of being reported to the developers of bc.
No, it is compliant with the POSIX specification:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
Quoting:
For bases greater than 16, each digit shall be written as a separate
multi-digit decimal number. Each digit except the most significant
fractional digit shall be preceded by a single <space>. For bases from 17
to 100, bc shall write two-digit decimal numbers; for bases from 101 to
1000, three-digit decimal strings, and so on. For example, the decimal
number 1024 in base 25 would be written as:
01 15 24
and in base 125, as:
008 024
And of course, POSIX specifies it this way because *that's how it has
always acted* in historical implementations.
I have yet to see any real-life application that requires numbers to
be written in base 36 using 0..9A..Z as the digits, *especially* from
a shell script, of all things.
That said, I have no objection to Chet adding such a feature to Bash,
if he can think of a sane way to do it. If you have a patch that
implements it, it's possible he'll be willing to review it.