| dec2base | tools | dec2base |
dec2base -- Convert decimal number to another base
dec2base input base
This script is a number base conversion routine to convert decimal numbers to another base.
Digits for values greater than 9 are assigned sequentially to the alphabet. For example, the value 10 is mapped to an a, value 11 is mapped to b, etc.
IRAF does provide the built-in function "radix" for this operation. However, it fails with bases larger than 16 (hexidecimal).
1. Convert the value 31 to base 2 (binary).
cl> dec2base 31 2 11111 cl> lpar dec2base input = 31 Base 10 number to convert base = 2 Base to convert to (output = "11111") Output: String representation of the conversion (verbose = yes) Print result to standard output?
2. Convert the value 31 to base 8 (octal)
cl> dec2base 31 8 37
3. Convert the value 31 to base 16 (hexidecimal)
cl> dec2base 31 16 1f
4. Convert the value 31 to base 10 (decimal)
cl> dec2base 31 10 31
This script is dependent on the host operating system character set. The only requirement is that the alphabet be represented sequentially and in increasing number from A/'a' to Z/'z'. ASCII satisfies this requirement. If this requirement is not met, the results will be unpredictable.
Since values greater than 9 are mapped into the alphabet, and there are only 26 letters in the alphabet, only numbers up to base 36 can be supported.
For assistance using this or any other tasks, please contact help@stsci.edu or call the help desk at 410-338-1082.