How can I get zeros and ones that make a file? For example, how can I open a file with Python and get the zeros and ones that make it up? And convert those zeros and ones again to a file?
Thanks for your help!
How can I get zeros and ones that make a file? For example, how can I open a file with Python and get the zeros and ones that make it up? And convert those zeros and ones again to a file?
Thanks for your help!
This question is very vague, so I will try and answer some of the possible questions I think you are asking.
Some files need to have the "binary" versions of the files opened. A easier way to think of this would be opening a file in "raw" (binary) vs "plaintext" (text) mode.
Often API's that work with PDF files, and certain other extensions use this to open the files properly since they contain characters that are encoded to be unreadable, and use headers that would garble the files as plain strings.
To do this change the mode of a call to open()
to any of these :
For example:
with open("filename.pdf", "rb") as pdf_file:
... # Do things
If you are looking to open a file and get a binary association to a character you can use the ord() function combined with the bin() function:
ord("A") # 65
bin(ord("A")) # '0b1000001'
You can then loop through each character of a file and find a binary representation of each letter this way. This is often used in cryptography, like I did for this project.
If neither of those two solve your issues please clarify what you mean in the original question so I can better address it.