manual base encoding/decoding