I want to read a file as binary data and convert the read binary data into a 1-bit array.
For example, a file called a.png is read as a binary file and the data is arranged in 1-bit arrays
(Example) [0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, ...]
I want to do something, but I don't know how.
I would appreciate it if you could tell someone.
Answer # 1
Handling binary data in Python | Reading and hexadecimal display
Python binary data
Reviewing Python3 (binary data)
I wrote this code.
file_path = "a.txt" data =  with open (file_path, 'rb') as f: data = f.read () for d in data: print (d) print (list (map (lambda x: int (x), format (d, '08b'))))
Answer # 2
read byte by byte I don't know if the value is the most significant or least significant value, but it takes the bit pattern and bit AND in order from the end, and adds 0 or 1 to the list depending on the result.
Or, make the byte value a binary string with
bin (), make it an 8-digit binary string, then
list ()Do you want to add it?
- python - how to sort a 3d array
- python - array i want to erase all the values in an array
- python - indexerror: list index out of range does the array not exist?
- array - maximum and minimum of python integers
- i want to increase a python 3d array to 4d and add a linear array
- python expected 1d or 2d array, got 3d array instead error in function creation
- python - i don't know how to read and write files in binary (bitwise)
- python - failed to receive binary data (base64) with lambda
- python - how to make a non-rewritable array rewritable
- in python, i want to extract an array from a number reference
- python i want to convert a multidimensional array back to an image
- python - i want to create an array by generating integer random numbers with constraints
- python - i want to make a list with tuple elements into a simple array
- python - i want to change a 2d ndarray array to a primary list
- python - i want to sort a 2d array
- python - i want to take the nth to mth slices in a numpy array sometimes n is positive and sometimes it is negative
- i want to create a list (one-dimensional array) of the maximum value of multiple arrays with python
- python - how to make a multidimensional array by for statement and multiplication
- i want to make a 2d array of python n * n
- python 3x - i want to get the nth array with an argument using python3 argparse
- get gogole search screen automatically with python
- python - it takes too much time to do with big data with many for
- i want to extract one character string of text that exists in multiple files with python
- python - i want to ignore the header and loop
- python dataframe how to save csv divided by date
- information entered in html in vuejs cannot be sent to python with cgi
- python - the library installed by pip cannot be imported no module named'selenium'
- python - about nameerror when trying to run cython on jupyter lab
- python - i want to display the next window when i press the button!
- i want to display screens with different window sizes when i press the [python/tkinter] tab