Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Warren Young
On Aug 31, 2015, at 11:54 AM, Mike - st257 wrote: > > define stanzas don't > replicate the behavior as seen when used via piping or interactively. :-/ Again, it comes down to order of evaluation. You can look at the following in three stages: define bin_to_hex(b) { obase=16; ibase=2; retur

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Mike - st257
On Mon, Aug 31, 2015 at 1:06 PM, Warren Young wrote: > On Aug 31, 2015, at 10:05 AM, Mike - st257 wrote: > > > > On Mon, Aug 31, 2015 at 11:15 AM, Warren Young wrote: > > > >> ibase=A and obase=A > > > > Not sure how this helps me with my most recent example of bin_to_hex > where > > the ibase

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Mike - st257
On Mon, Aug 31, 2015 at 12:50 PM, Gordon Messmer wrote: > On 08/31/2015 05:55 AM, Mike - st257 wrote: > >> I'm not an expert in bc, so I might be wrong, but it looks like setting >>> >the ibase inside a function is simply too late. ibase affects how bc >>> >interprets input. >>> > >>> >> Th

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Warren Young
On Aug 31, 2015, at 10:05 AM, Mike - st257 wrote: > > On Mon, Aug 31, 2015 at 11:15 AM, Warren Young 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_h

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Gordon Messmer
On 08/31/2015 05:55 AM, Mike - st257 wrote: I'm not an expert in bc, so I might be wrong, but it looks like setting >the ibase inside a function is simply too late. ibase affects how bc >interprets input. > Thanks Gordon. Big bummer given that behavior. :-/ I suppose that depends on what you

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Mike - st257
On Mon, Aug 31, 2015 at 11:15 AM, Warren Young wrote: > On Aug 31, 2015, at 6:55 AM, Mike - st257 wrote: > > > > I suppose my only options for this are to use shell functions or write a > > script using a language that handles things properly (sanely?). > > No, there’s a fairly common hack aroun

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Warren Young
On Aug 31, 2015, at 6:55 AM, Mike - st257 wrote: > > I suppose my only options for this are to use shell functions or write a > script using a language that handles things properly (sanely?). No, there’s a fairly common hack around this problem: ibase=A and obase=A *always* means “base 10” rega

Re: [CentOS] [OT] GNU bc base conversion

2015-08-31 Thread Mike - st257
On Fri, Aug 28, 2015 at 4:14 PM, Warren Young wrote: > On Aug 28, 2015, at 9:50 AM, Gordon Messmer > 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 n

Re: [CentOS] [OT] GNU bc base conversion

2015-08-28 Thread Warren Young
On Aug 28, 2015, at 9:50 AM, Gordon Messmer 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 i

Re: [CentOS] [OT] GNU bc base conversion

2015-08-28 Thread Gordon Messmer
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 wrong, but it looks like setting the ibase inside

[CentOS] [OT] GNU bc base conversion

2015-08-28 Thread Mike - st257
Hello CentOS List Members, 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. No doubt the syntax is in some way wrong, but when I test from the CLI and the right values are returned, I h