#!/bin/sh ######################################################################### # # FILE : base # DATE : 26.01.2001 # AUTHOR : Patrick Meier / patrick.meier@gmx.net # DESCRIPTION : print number to different bases # # Copyrigth (C) 2001 by Patrick Meier, Switzerland # ######################################################################### PN=`basename "$0"` STARTSTRING="==>" ######################################################################### # Usage ######################################################################### Usage() { echo "$PN - print number to different bases" echo "usage: $PN [number ...]" exit 1 } ######################################################################### # PrintBases ######################################################################### 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 *) echo "${STARTSTRING}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 <