On Mon, Aug 31, 2015 at 12:50 PM, Gordon Messmer <gordon.messmer@xxxxxxxxx> 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. >>> > >>> >> Thanks Gordon. >> Big bummer given that behavior. :-/ >> > > I suppose that depends on what you're trying to accomplish. Most > conversions you can do entirely within bash, if that's your goal. > Yes indeed it can be done in bash. I figure at this point I'm going that route. Thanks! > > function dec_to_hex () { printf '%x\n' $1; } > function hex_to_dec() { printf '%d\n' $(( 16#$1 )); } > function hex_to_bin() { echo 'obase=2;' $(( 16#$1 )) | bc; } > > $ dec_to_hex 10 > a > $ hex_to_dec a > 10 > $ hex_to_bin a > 1010 > > > _______________________________________________ > CentOS mailing list > CentOS@xxxxxxxxxx > https://lists.centos.org/mailman/listinfo/centos > -- ---~~.~~--- Mike // SilverTip257 // _______________________________________________ CentOS mailing list CentOS@xxxxxxxxxx https://lists.centos.org/mailman/listinfo/centos