Operating System - HP-UX
1833758 Members
2593 Online
110063 Solutions
New Discussion

converting bin to hex with bc or dc. ?

 
SOLVED
Go to solution
rveri
Super Advisor

converting bin to hex with bc or dc. ?

Hi Experts,

How to calculate binary , hex , and decimal using the bc or dc.

I am having 10110 ( Binary) want to convert to (a) Decimal (b) Hexadecimal.

How can I do that?

Thanks,
Veri.
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: converting bin to hex with bc or dc. ?

It's important to specify the output base (obase) first because otherwise you must specify everything in the new input base.

bc
obase=16
ibase=2
10110

quit
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: converting bin to hex with bc or dc. ?

Hi Veri:

You can do :

# echo "ibase=10;obase=16;255"|bc

...or you can use 'prinf' like:

# printf "%#x\n" 255

See the manpages for 'printf' for more details.

Regards!

...JRF...
Raj D.
Honored Contributor

Re: converting bin to hex with bc or dc. ?

You can try like this :


1. bin to hex

# echo "obase=16 \n ibase=2 \n 10110" | bc

2. bin to dec

# echo "obase=10 \n ibase=2 \n 10110" | bc

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
rveri
Super Advisor

Re: converting bin to hex with bc or dc. ?

thanks all.