Hex to Binary Conversion routine

Hi,
Does anybody have a Hex to Binary proc already written.  I know I could do it by parsing out the input string and then using a big case statement, but I'm sure there's a better/quicker way.  Also, I don't really have time to write it in the next few days.  I'm running ksh on an aix box.
Thanks,
Bret
badreeceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cotec1Commented:
I can't rember where I found this but I think it will do what you want (and more).

Msg () {    for i    do echo "$PN: $i" >&2    done}
Fatal () { Msg "$@"; exit 1; }PrintBases () {    # Determine base of the number
    for i    do      case "$i" in          0b*)            ibase=2;;      # binary
          0x*|[a-f]*|[A-F]*)      ibase=16;;      # hexadecimal          0*)                  ibase=8;;      # octal
          [1-9]*)            ibase=10;;      # decimal          *)            Msg "illegal number $i - ignored"
            continue;;      esac
      # Remove prefix, convert hex digits to uppercase (bc needs this)
      number=`echo "$i" | sed -e 's:^0[bBxX]::' | tr '[a-f]' '[A-F]'`
      # Convert number to decimal      dec=`echo "ibase=$ibase; $number" | bc`
      case "$dec" in          [0-9]*)      ;;                  # number ok          *)            continue;;            # error: ignore
      esac      # Print all conversions in one line      echo `bc <<!
          obase=16; "hex="; $dec          obase=10; "dec="; $dec
          obase=8;  "oct="; $dec          obase=2;  "bin="; $dec!    ` | sed -e 's: :      :g'
    done}while [ $# -gt 0 ]do    case "$1" in      --)      shift; break;;      -h)      Usage;;
      -*)      Usage;;      *)      break;;                  # first number    esac    shiftdoneif [ $# -gt 0 ]then
    PrintBases "$@"else                              # read from stdin    while read line    do
      PrintBases $line    donefi
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
badreeceAuthor Commented:
Thanks,
b...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.