0

I haven't experienced a binary file analysis so far. I am trying to decode the binary file with python. How would I convert the following bytes object that has a length of 3 to integer or string with Python?

e.g.) b'x05/x18/x27' => ????

James Z
  • 12,209
  • 10
  • 24
  • 44
  • does that solve your problem ? https://stackoverflow.com/questions/606191/convert-bytes-to-a-string – kareem_emad Sep 19 '20 at 01:32
  • 2
    I'm not sure what you think "byte3" means. Did you mean, a `bytes` object that has a *length* of 3? In particular, I guess your example is supposed to be `b'\x05\x18\x27'`? Okay, then, what is the *rule that tells you* what the integer result, or string result, should be? What do you think the output should be for that specific input, and what is the reasoning that gets you there? – Karl Knechtel Sep 19 '20 at 01:36
  • When you say that you want to "decode" a "binary file", exactly what kind of file? Is it used for a particular purpose? If so, does it have a particular **file format** that is documented somewhere? If so, did you **read** the documentation? – Karl Knechtel Sep 19 '20 at 01:37
  • I am a beginner. I could not tell it well. You are right. The bytes object has a length of 3. b'\x05\x18\x27'. I thought it should be 4-digit number like a '1000' when I applied b'\x05\x18\x27b'.decode('utf-8'). However, It was corrupted. The rule of binary file which I want to decode has not been published yet. So it has no document. But somehow I would have like to decode it by myself. – user13691392 Sep 19 '20 at 04:53
  • Maybe `int.from_bytes(b'\x05\x18\x27','big')`? Or even `int.from_bytes( b'\x05\x18\x27b', 'big')` ? – JosefZ Feb 13 '21 at 19:42

0 Answers0