I have use socket TCP/IP to receive a bit stream of an FPGA board in Octave and Python.
In Octave, with
[data_tcp1,len_tcp]=recv(client_tcp, 70848, MSG_WAITALL);
I received the data with dimension 70848 with datatype is uint8
Now In python, I would have the same behavior like Octave, so I tried:
data_tcp1 = client_tcp.recv(70848)# data in byte
I got the same size: 70848 but with < class byte >. There is a lot of option in python that I have tried to get the same result like Octave.
data_tcp1 = client_tcp.recv(70848).decode('ISO-8859-1')
or,
data = client_tcp.recv(70848).decode('utf-8', 'ignore')
or, data = client_tcp.recv(70848).decode()
Is there any explication in this command? What is the option should I use to obtain the same behavior like in Octave?
Thanks with best regards!
CodePudding user response:
.decode
method of bytes
instance is used for getting str
(string) based on that bytes
instance. If you wish to turn each byte into number you might use list
, consider following simple example
data = b"\x00\x0F\xFF"
values = list(data)
print(values) # [0, 15, 255]