Displaying 5 results from an estimated 5 matches for "bcrc".
Did you mean:
bcc
2015 Aug 28
2
[OT] GNU bc base conversion
...ecimal to binary or hex works fine, but not binary or hex to decimal and
so forth.
No doubt the syntax is in some way wrong, but when I test from the CLI and
the right values are returned, I have to wonder.
Other than a few other define statements, the only other option I have set
is scale=5 in my bcrc.
In reference to the order of (o|i)base parameters, I have specified obase
before ibase [0].
[0] http://docstore.mik.ua/orelly/unix/upt/ch49_03.htm
See below for my examples.
Thanks!
]$ echo "bin_to_dec(1001)" | bc
1001
# should be decimal 9
]$ echo "obase=10; ibase=2; 1001&quo...
2015 Aug 31
0
[OT] GNU bc base conversion
...gt; the ibase inside a function is simply too late. ibase affects how bc
> interprets input.
>
Thanks Gordon.
Big bummer given that behavior. :-/
I had (and did test) definitions for other conversions (though I didn't
post them), but this one also drives it home.
~]$ grep bin_to_hex ~/.bcrc
define bin_to_hex(b) { obase=16; ibase=2; return b; }
~]$ echo "bin_to_hex(10101011)" | bc
9A2113
# so we're sending in a string with implied base10 ... sure enough matches
what BC errantly decided to do
~]$ echo "obase=16; 10101011" | bc
9A2113
~]$ echo "obase=16; ib...
2015 Aug 31
0
[OT] GNU bc base conversion
...gt; 10101011
>
> Result: AB, as expected.
>
Thank you.
We're in agreement, your solution _does_ work when piped or interactively.
Any order does not work from a definition stanza since base10 is
(apparently) not capable of being overrode with definitions.
tmp]$ grep bin_to_hex ~/.bcrc
#define bin_to_hex(b) { obase=16; ibase=2; return b; }
define bin_to_hex(b) { ibase=A; obase=A; obase=16; ibase=2; return b; }
tmp]$ echo "bin_to_hex(10101011)" | bc
9A2113
tmp]$ echo "ibase=A; obase=A; obase=16; ibase=2; 10101011" | bc
AB
tmp]$ echo "obase=16; ibase=2; 10...
2015 Aug 28
3
[OT] GNU bc base conversion
On Aug 28, 2015, at 9:50 AM, Gordon Messmer <gordon.messmer at gmail.com> wrote:
>
> On 08/28/2015 07:15 AM, Mike - st257 wrote:
>> Thoughts as to why my BC functions aren't properly converting between bases?
>>
>> Decimal to binary or hex works fine, but not binary or hex to decimal and
>> so forth.
>
> I'm not an expert in bc, so I might be
2015 Aug 31
2
[OT] GNU bc base conversion
On Aug 31, 2015, at 10:05 AM, Mike - st257 <silvertip257 at gmail.com> wrote:
>
> On Mon, Aug 31, 2015 at 11:15 AM, Warren Young <wyml at etr-usa.com> wrote:
>
>> ibase=A and obase=A
>
> Not sure how this helps me with my most recent example of bin_to_hex where
> the ibase within the define clause wasn't honored.
That?s because your bin_to_hex function