You can refer to the below screenshot for the output To print the converted string, I have used print(string). In this example, I have taken a string as (‘python guides’), To convert the string into bytearray ASCII, I have used string = bytes(str(‘Python guides’).encode(“ascii”)).Įxample: string = bytes(str('Python guides').encode("ascii"))
#Convert string to number python 2.7 how to
Here, we can see how to convert string to bytearray ASCII in python You can refer to the below screenshot for the output. To print the hex string converted to a byte array, I have used print(newstring). The omhex() method returns a required string containing hex numbers. In this example, I have taken a hex_string = “1A” and to convert that string to bytearray I have used newstring = omhex(hexa_string). Now, we can see how to convert hex string to byte array in python Python string to a byte array without b Python hex string to byte array To print the encoded string, we have to use print(string). String = base64.b64decode("Pythonguides")
To convert the string into UTF-8, I have used newstring = bytes(string, ‘utf-8’). In this example, I have taken a string as “Python guides”. Now, we can see how to convert a string to byte array utf-8 in python
Python string to byte array encoding Python string to byte array UTF-8