helm/bin/base

13 lines
342 B
Plaintext
Raw Normal View History

2017-04-25 00:16:53 -07:00
#!/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
2017-04-25 00:16:53 -07:00
# 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)
2017-04-25 00:16:53 -07:00
bc <<< "obase=${3:-10};ibase=$1;$2"