Displaying 2 results from an estimated 2 matches for "dec_to_hex".
2015 Aug 31
1
[OT] GNU bc base conversion
...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.
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
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