Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert base64 byte to string byte without extra slashes and b''

I want convert this base64 string to a byte string like this:

base64:

XHhjXHg0OFx4ODNceGU0XHgwXHhlOFx4Y2NceDAwXHgwMFx4MDBceDQxXA==

string byte:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

\xc\x48\x83\xe4\x0\xe8\xcc\x00\x00\x00\x41\

I made this code:

import base64

bstring = "XHhjXHg0OFx4ODNceGU0XHgwXHhlOFx4Y2NceDAwXHgwMFx4MDBceDQxXA=="
decoded = base64.b64decode(bstring)
print(decoded)

And this is the output:

b'\\xc\\x48\\x83\\xe4\\x0\\xe8\\xcc\\x00\\x00\\x00\\x41\\'

So this is the problem. I don’t wanna double slash and b” so how can I convert it like this (I need byte): \xc\x48\x83\xe4\x0\xe8\xcc\x00\x00\x00\x41\?

>Solution :

Just run the .decode() method on the resulting bytestring:

import base64

bstring = "XHhjXHg0OFx4ODNceGU0XHgwXHhlOFx4Y2NceDAwXHgwMFx4MDBceDQxXA=="
decoded = base64.b64decode(bstring).decode()
print(decoded)  # => \xc\x48\x83\xe4\x0\xe8\xcc\x00\x00\x00\x41\
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading