Issue
myNumber=$(date +%s) # big number in decimal
myNumberInB58=$(toBase58 $myNumber)
toBase58() {
# <your answer here>
}
What is the most elegant and/or concise way to encode an integer in Base58?
Solution
Here's another version:
# Order-Preserving Base58 (OPB58).
# Also supports negative numbers.
int2b58() {
# Omit IOlo
local n="$1" i BASE58=$(echo {0..9} {A..H} {J..N} {P..Z} {a..k} {m..n} {p..z} | tr -d ' ')
((n < 0 )) && printf -- '-' && n=$((-n))
for i in $(echo "obase=58; $n" | bc); do
printf ${BASE58:$(( 10#$i )):1}
done; echo
}
Answered By - Elifarley Answer Checked By - David Goodson (WPSolving Volunteer)