Simplify Base32 and Base64 conversions
Summary:
Generalize ConvertBits a bit to also be usable for the existing Base32 and Base64 convertions (rather than just for Bech32).
Backport of core PR11630.
Depends on D5734.
The key_io.cpp changes are not ported because they are segwit related,
however some cashaddrenc.cpp and util_tests.cpp changes were required.
Test Plan:
ninja all check check-functional
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Differential Revision: https://reviews.bitcoinabc.org/D5735