I have a byte data is like: b'\xc4\x03\x00\x00\xe2\xecqv\x01'.
How do I convert this to integer like index by index.
-
It depends on how you want to interpret that as integers. You can take each byte and convert it to integer, or each bit, or each 16-bit word or interpret the whole data as one integer, or anything else. In the end it sums up to question: how did you get that binary data in the first place?zvone– zvone2019-03-25 07:31:03 +00:00Commented Mar 25, 2019 at 7:31
Add a comment
|
3 Answers
a bytes object is basically already a (immutable) sequence of integers.
b = b'\xc4\x03\x00\x00\xe2\xecqv\x01'
b[0] # 196
lst = list(b)
# [196, 3, 0, 0, 226, 236, 113, 118, 1]