base conversion - How to convert decimal number to Base58 in Bash -
mynumber=$(date +%s) # big number in decimal mynumberinb58=$(tobase58 $mynumber) tobase58() { # <your answer here> } what elegant and/or concise way encode integer in base58?
would do?
a=( {1..9} {a..h} {j..n} {p..z} {a..k} {m..z} ) tobase58() { # todo: check $1 valid number local nb=$1 b58= fiftyeight=${#a[@]} while ((nb)); b58=${a[nb%fiftyeight]}$b58 ((nb/=fiftyeight)) done printf '%s\n' "$b58" }
Comments
Post a Comment