Read the binary file content like this:
with open(fileName, mode='rb') as file: # b is important -> binary fileContent = file.read()
then “unpack” binary data using struct.unpack:
The start bytes: struct.unpack("iiiii", fileContent[:20])
The body: ignore the heading bytes and the trailing byte (= 24); The remaining part forms the body, to know the number of bytes in the body do an integer division by 4; The obtained quotient is multiplied by the string 'i'
to create the correct format for the unpack method:
struct.unpack("i" * ((len(fileContent) -24) // 4), fileContent[20:-4])
The end byte: struct.unpack("i", fileContent[-4:])
Related Posts:
- Reading a binary file with python
- What is “2’s Complement”?
- Why prefer two’s complement over sign-and-magnitude for signed numbers?
- bad operand types for binary operator “&” java
- How do you express binary literals in Python?
- Binary numbers in Python
- What does the ‘b’ character do in front of a string literal?
- What does the ‘b’ character do in front of a string literal?
- How to convert string to binary?
- Convert hex to binary
- What is the difference between signed and unsigned binary
- Convert decimal to binary in python
- Converting binary to decimal integer output
- Python int to binary string?
- How to convert string to binary?
- binary bomb lab phase 6
- How is overflow detected in two’s complement?
- How to convert ‘binary string’ to normal string in Python3?
- Are the shift operators (<<, >>) arithmetic or logical in C?
- How to used the alphabet binary symbols
- What is the “biggest” negative number on a 4-bit machine?
- Converting integer to binary in python
- Python conversion from binary string to hexadecimal
- convert decimal numbers to excess-127 representations
- Converting an integer to binary in C
- Is it possible to program in binary?
- Does Python have a ternary conditional operator?
- How do I install opencv using pip?
- How do I compare two strings in python?
- Purpose of “%matplotlib inline”
- Curve curvature in numpy
- How do I update Anaconda?
- TypeError: ‘str’ object is not callable (Python)
- Dijkstra’s algorithm in python
- python – how to get the data from an plt.imshow()?
- How to create a GUID/UUID in Python
- What are data classes and how are they different from common classes?
- Tensorflow import error: No module named ‘tensorflow’
- Python random function
- Converting NumPy array into Python List structure?
- How do you get the logical xor of two variables in Python?
- Replace ‘ with \’ in a string
- C++ – Decimal to binary converting
- Arrays used as indices must be of integer (or boolean) type
- python pip – install from local dir
- Are static class variables possible in Python?
- Why am I getting “LinAlgError: Singular matrix” from grangercausalitytests?
- How does the @property decorator work in Python?
- ‘method’ object is not subscriptable. Don’t know what’s wrong
- How to remove punctuation in python?
- How do I copy a file in Python?
- EOFError: Ran out of input
- Get Color Palettes from ColorHunt.co in Python
- syntax error when using command line in python
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- AttributeError: Module Pip has no attribute ‘main’
- django:django.core.exceptions.AppRegistryNotReady: Apps aren’t loaded yet
- Can I force pip to reinstall the current version?
- Removing pip’s cache?
- How to get the current time in Python
- Improve subplot size/spacing with many subplots in matplotlib
- Can I run Keras model on gpu?
- How to check whether a pandas DataFrame is empty?
- Convert columns to string in Pandas
- How can I use numpy.correlate to do autocorrelation?
- What does `<>` mean in Python?
- Add a new item to a dictionary in Python
- reducing number of plot ticks
- How can I add new keys to a dictionary?
- Convert pandas data frame to series
- Decorators with parameters?
- How do I get a python program to do nothing?
- inserting characters at the start and end of a string
- Python 3 – ValueError: not enough values to unpack (expected 3, got 2)
- Append a tuple to a list – what’s the difference between two ways?
- No module named Image
- How to fix “TypeError: len() of unsized object”
- ValueError: Unknown projection ‘3d’ (once again)
- Difference between len() and .__len__()?
- Python: AttributeError: ‘_io.TextIOWrapper’ object has no attribute ‘split’
- Python/Django: log to console under runserver, log to file under Apache
- TypeError: unsupported format string passed to list.__format__
- Getting “socket.error: [Errno 61] Connection refused” python paramiko
- python setup.py uninstall
- ImportError: No module named cv2
- How to open every file in a folder
- Python iteration over non-sequence
- How do I convert a string to a double in Python?
- _csv.Error: field larger than field limit (131072)
- How do I rotate an image around its center using Pygame?
- How can I copy a Python string?
- Issue with virtualenv – cannot activate
- Can I set max_retries for requests.request?
- Package libffi was not found in the pkg-config search path REDHAT6.5
- Line is too long. Django PEP8
- TypeError: zip argument #2 must support iteration
- CS231n: How to calculate gradient for Softmax loss function?
- How to create a new database using SQLAlchemy?
- Numpy matrix to array
- Update post / page using API + python