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 3x - how to add a two-dimensional array
- python - typeerror when calculating the array of images called by imageopen ()
- python - i want to create a binary mask by comparing two elements and setting the smaller one to 0
- how to convert the array type of the value extracted by the condition specification from the python array to the integer type?
- python - i want to divide a binary number into two, store it in a list, and represent it in a different decimal number
- i want to convert "array string" to an array in python
- python - i want to store a 3d array in an array using numpy
- i want to get an array of directory names and file names in python and create a csv
- python - array elements cannot be used as function arguments ??
- i want to make a python array one-dimensional, but it doesn't work
- python - handling of 1d array data when using the predict function in keras
- python - i want to swap the first half and the second half of the array and put them in different arrays
- how to use python 2d array
- python - i want to store an object in an array
- i want to manipulate the strings inside a python array
- python 3x - i want to get the nth array with an argument using python3 argparse
- python - about replacement of data in two-dimensional array
- python - how to sort a 3d array
- python - read the multidimensional array saved by csv
- python - i want to delete non-multiples from the array string (sequence + \ n)