The base64.b16decode()
method decodes a bytes-like object using Base16 alphabets into plain text.
We can import b16decode
from base64
using the following code:
from base64 import b16decode
The declaration of the base64.b16decode()
method is as follows:
base64.b16decode(b_string)
The method returns the decoded byte-string.
The code below demonstrates the use of base64.b16decode()
:
from base64 import b16encodefrom base64 import b16decodeb_str = b'Python is awesome!'print('Data type of \'s\': ', type(b_str))enc_str = b16encode(b_str) # encodedec_str = b16decode(enc_str) # decodeprint('Data type of decoded \'dec_str\': ', type(dec_str))print('Decoded string: ', dec_str)
In line 4, a byte string is initialized and stored in b_str
. The next line prints the type of b_str
. In line 7, the string is encoded, then in line 8, the string is decoded, and finally line 9 prints the type of the encoded string. Lastly, in line 11, the encoded string is printed.
Free Resources