...making Linux just a little more fun!

2-Cent Tips

Two-cent Tip: number conversion between between base-x to base-y

Mulyadi Santosa [mulyadi.santosa at gmail.com]

Sat, 18 Jul 2009 20:35:59 +0700

For those who needs quick help on number conversion between base-x to base-y, bc can lend a help here. For example, what's the hexadecimal form of 116?:

$ echo 'obase=16; 116' | bc

And what does binary 11010101 look in decimal?

$ echo 'ibase=2; 11010101' | bc

By doing below step, you directly convert binary 11010101 to hexadecimal:

$ echo 'obase=16; ibase=2; 11010101' | bc

Note that "obase" must preced "ibase" in order to make a correct final result.


Mulyadi Santosa
Freelance Linux trainer
blog: the-hydra.blogspot.com

[ Thread continues here (6 messages/6.90kB) ]

Talkback: Discuss this article with The Answer Gang

Copyright © 2009, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 165 of Linux Gazette, August 2009