简体   繁体   中英

Base64 index table

I am working on a Python program where I have a long binary string and want to convert it into the corresponding characters based on the base64 index table.

Is there any efficient way you can take '000000' and turn it into 'A' , '000001' for 'B' , etc? I've tried looking up at the base64 library but can't seem to find a way. I suppose I could just make a dictionary of the corresponding values but just wanted to see if there was a more elegant way.

In base 64 to represent 5 zeros you'd need to apply it in the following way: AAAAA If it is a repetitive striing - meaning the same one / not a user input or dynamic of sorts then better use a simple string=0000; print(string) Note that it is case sensitive - in Python you can just use this or something similar:

from base64 import b64encode, b64decode
#hexideximal to base64 in python
h = '00000'
b64 = b64encode(bytes.fromhex(h)).decode()
print(b64)

I think should work fine this way - :) update i just reread that you are trying to decode binary to base64 it works all the same - just alter the the code slightly to something like so :

import base64   

 base64.b64decode(ooooo) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM