Answers for "string to bytes example"

7

python string to bytes

s = 'abc'

# string to bytes using bytes()
b = bytes(s, encoding='utf-8')
print(type(b))							# <class 'bytes'>
print(b)								# b'abc'

# bytes to string using decode()
s = b.decode()
print('Original String =', s)			# Original String = abc
s = 'xyz'								

# string to bytes using encode()
b = s.encode(encoding='utf-8')
print(b)								# b'xyz'
s = b.decode()
print('Original String =', s)			# Original String = xyz
Posted by: Guest on April-19-2021
4

convert string to byte java

String example = "Convert Java String";
  byte[] bytes = example.getBytes();
Posted by: Guest on April-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language