I want to read the raw binary of a file and put it into a string. Currently I am opening a file with the "rb" flag and printing the byte but it's coming up as ASCII characters (for text that is, for video and audio files it's giving symbols and gibberish). I'd like to get the raw 0's and 1's if possible. This needs to work for audio and video files as well so simply converting the ascii to binary isn't an option.
with open(filePath, "rb") as file:
byte = file.read(1)
print byte
print bin(ord(byte)). Theord()function returns the integer value of the byte when the argument is a one character 8-bit string. Lastly Thebin()function convert integer numbers to a binary string of 0 and 1 characters for printing with a0bprefix so you'll see something like0b1100001printed.