简体   繁体   中英

Base64 to decimal

Playing around with conversions in base64 with Python but I have hit a roadblock with trying to convert b64 to decimal.

The following code is suggested on stackoverflow previously but doesn't seem to work for me.

I looked up the error and it appears that this means it can't decode b6 because it is already decoded...

b6 = 'FhY='
print(' '.join([ str(ord(c)) for c in b6.decode('base64') ]))

#expectedoutput = 22 22 
#'str' object has no attribute 'decode'

Bytes objects have decode function. Strings do not. The leading b on the string matters.

b6 = b'FhY='

Then, decode('base64') is not correct and will return error saying the codec doesn't exist.

Here is what you need, which returns a joined string of two decimal values

>>> ' '.join(map(str, base64.decodebytes(b6)))
'22 22'

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