Use the built-in ord function.
with open("/bin/ls", "rb") as fin:
buf = fin.read()
bytes = map(ord, buf)
print bytes[:10]
output:
[127, 69, 76, 70, 2, 1, 1, 0, 0, 0]
Question
I have a raw binary data and I want to convert it into a readable text.
the text contains with something that is not readable, it has also special characters, like black box with NUL word or " N–[«´N–[« )› )ÿ " . I'm just new in python.
here's my code
import struct
file = open('rawbinary.txt')
text = file.read()
struct.unpack("iiiii", text[:20])
my output was:
(2113933569, 67305475, -80477197, 1536577129, 1312228259)
and if add this:
text[:10]
my output is
'\x01\x11\x00~\x03\x00\x03\x04\xf3\x03'
Am I doing it right? What is my next step?
Solution
Use the built-in ord function.
with open("/bin/ls", "rb") as fin:
buf = fin.read()
bytes = map(ord, buf)
print bytes[:10]
output:
[127, 69, 76, 70, 2, 1, 1, 0, 0, 0]