I have a line as follows:
b'\x00\x00\x00\x00\x07\x80\x00\x03'
How can I convert this to an array of bytes? ... and back to a string of bytes?
in python 3:
>>> a=b'\x00\x00\x00\x00\x07\x80\x00\x03' >>> b = list(a) >>> b [0, 0, 0, 0, 7, 128, 0, 3] >>> c = bytes(b) >>> c b'\x00\x00\x00\x00\x07\x80\x00\x03' >>>
From string to byte array:
a = bytearray.fromhex('00 00 00 00 07 80 00 03')
or
a = bytearray(b'\x00\x00\x00\x00\x07\x80\x00\x03')
and back to the line:
key = ''.join(chr(x) for x in a)
Source: https://habr.com/ru/post/1242691/More articles:Android OpenGL ES 2.0 limited to only 16 textures in memory? - javaWhat is the purpose of -Wbad-function-cast, why does it only apply to a direct return value? - cAndroid What is the difference between setVariable (BR.xyz, model) and databinding.setXYZ (model) - androidBarcode Scan Using - react-nativeHow to add a frame border to the camera? - react-native-cameraPHP and Royal Mail Tracking API - soapMatlab ShortEng number format via sprintf () and fprintf ()? - matlabEntity Framework attaches query with int array - sqlsocket.io + redis + expressjs cluster - get socket object in expressjs expression - node.jsHow to enable inline (isolated) groovy scripts? - elasticsearchAll Articles