Answers for "algorithm to convert int to bytes in python"

1

convert int to byte python

pythonCopy>>> (258).to_bytes(2, byteorder="little")
b'\x02\x01'
>>> (258).to_bytes(2, byteorder="big")
b'\x01\x02'
>>> (258).to_bytes(4, byteorder="little", signed=True)
b'\x02\x01\x00\x00'
>>> (-258).to_bytes(4, byteorder="little", signed=True)
b'\xfe\xfe\xff\xff'
Posted by: Guest on September-06-2020
9

python convert string to bytes

data = ""  			#string
data = "".encode()	#bytes
data = b"" 			#bytes
data = b"".decode() #string
data = str(b"")  	#string
Posted by: Guest on March-14-2020

Code answers related to "algorithm to convert int to bytes in python"

Python Answers by Framework

Browse Popular Code Answers by Language