how to convert a binary data into integer?
when I am using the wave_read.readframes()
I am getting the result in binary data such as /x00/x00/x00:/x16#/x05"
etc a very long string
when asked for single frame it gives @/x00
or \xe3\xff
or so
I want this individual 开发者_Go百科frame data in integer how can I convert them into integer to store them into array.
You want the struct module.
If you want each byte in its own int, then I'd go with map:
b = '\xde\xad\xbe\xef'
d = map(ord, b)
print d
[222, 173, 190, 239]
If, however, you are interested in more than 1 byte per int (or word, dword, etc), reduce could do you well (big-endian example):
reduce(lambda x, r: (x << 8) + r, d[1:3])
44478
精彩评论