2 Answers
2

Every single line should at least be comprehensible on its own. Single letter variables destroy that comprehension, meaning that anyone reading the code needs to read the entire code and mull it over for a while to even understand what it's meant to do. Something like current_byte = file_handle.read(1) is a lot more readable than b = f.read(1).

All the top-level code should be in either functions, methods or classes, and the file should have a main function, so that the pieces of this code can be understood and reused.

Running this through at least one linter such as flake8 and pycodestyle will give several tips to produce more pythonic code. For example, return (Res); should be written as return res - no parentheses or semicolon, and snake_case variable names.

There are several magic values like 80 and 4 which are hard to guess the meaning of. They should be pulled out as named variables or constants.

Instead of closing the file handle explicitly you should use a context manager like with open(…) as file_handle:. This ensures that the file handle will be closed even if there is an exception.

Rather than checking whether the current position in the file is at the end you should read until reading returns nothing.

There are assignment operators such as //= which can simplify some of your expressions.

A helpful exercise for detecting "hacky" code is to add type hints to it, and verifying it with mypy using strict settings (like not allowing Any). For example, it looks like the type of b would be Union[byte, str], which is a code smell - the variable is literally used for two different types of things.

You do a lot of manipulation of bytes to construct larger structures, which you then operate on. I'd suggest looking at the standard module struct which can do a lot of this for you in a way that is much easier to grasp.

Also, if you're going to read some bytes and then read them a second time, why not just read them into memory and operate on them twice?

Finally, your output appears to be text. Instead of write() why not use print ()?

Update:

Now that I'm not on a cell phone, let me expand a bit.

First, I'll point you to this excellent answer to a question on reading 32-bit values on SO. With that as a starting point, here's a function that does the same thing (plus a helper function that gets re-used below):