bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Base conversion within Base


From: IT1 Stuart Blake Tener, USNR
Subject: Re: Base conversion within Base
Date: Wed, 17 Sep 2014 08:46:28 -0400
User-agent: Internet Messaging Program (IMP) H3 (4.3.9)

Greg,

I was requesting a feature in bash, due to the bugulance of bc.

You are correct in theory, however, the construction you propose (due in no part to the fault of bash) yields an obfuscated and incomplete answer.

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.

10 11 01 12 13 14 01
^ position 10 (starting from zero is "A")
   ^ position 11 (starting from zero is "B")
etc...

If you convert to Hex in bc, you get no such rubbish!

echo "obase=16; 255" | bc
FF


Stuart


V/r,


--

IT1 Stuart Blake Tener, USNR, N3GWG (Extra), MROP
HQ NORAD / US NORTHCOM
NR JTF-CS DET EAST - UIC 84245

Las Vegas, NV / Boulder, CO / Philadelphia, PA / Beverly Hills, CA

(310) 358-0202 Mobile Phone
(215) 338-6005 Google Voice

e-mail: stuart.tener@bh90210.net



Quoting Greg Wooledge <wooledg@eeg.ccf.org>:

On Tue, Sep 16, 2014 at 02:45:42PM -0400, IT1 Stuart Blake Tener, USNR wrote:
It is rather simplistic to perform a conversion of a number from any
base to base 10 in bash using such construction as: echo $((36#AB1CDE1))

However, the greatness of the foregoing notwithstanding, it would be
most utilitarian indeed to have the ability to do base conversion from
base 10 to any other base as easily as is capable with the
aforementioned construction.

While such a feature does not exist within Bash, you can always use
bc to do it:

imadev:~$ echo "obase=36; 22435208137" | bc
 10 11 01 12 13 14 01






reply via email to

[Prev in Thread] Current Thread [Next in Thread]