to get a binary representation, I think you will need to import binascii, then:
byte = f.read(1) binary_string = bin(int(binascii.hexlify(byte), 16))[2:].zfill(8)
or, broken down by:
import binascii filePath = "mysong.mp3" file = open(filePath, "rb") with file: byte = file.read(1) hexadecimal = binascii.hexlify(byte) decimal = int(hexadecimal, 16) binary = bin(decimal)[2:].zfill(8) print("hex: %s, decimal: %s, binary: %s" % (hexadecimal, decimal, binary))
will output:
hex: 64, decimal: 100, binary: 01100100
source share