helm/bin/base
2017-12-06 01:39:10 -05:00

13 lines
342 B
Bash
Executable file

#!/usr/bin/env bash
# Converts a number from one base to another. DEST_RADIX is optional and
# defaults to 10.
#
# Usage: base SRC_RADIX NUMBER DEST_RADIX
# Examples:
# + base 2 110 #=> 6 (110_2 => 6_10)
# + base 10 9 8 #=> 11 (9_10 => 11_8)
# + base 16 FF #=> 255 (FF_16 => 255_10)
bc <<< "obase=${3:-10};ibase=$1;$2"