Reputation: 31
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.
Upvotes: 3
Views: 53
Reputation: 1
If you have Python v.3, you can use the int_from_bytes() function:
int.from_bytes(b'\xc4\x03\x00\x00\xe2\xecqv\x01', byteorder='big')
Upvotes: 0
Reputation: 46921
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]
Upvotes: 2
Reputation: 42796
Just access throug indexes:
>>> b = b'\xc4\x03\x00\x00\xe2\xecqv\x01'
>>> b[0]
196
>>> for i in b:
... print(i)
...
196
3
0
0
226
236
113
118
1
Upvotes: 0