Jul-21-2018, 03:06 PM
I'm trying to understand this code:
I would appreciate any help decoding this for me.
Thanks,
malonn
def readSize(self): b1 = ord(self.read(1)) if b1 & 0b10000000: # 1 byte return b1 & 0b01111111 elif b1 & 0b01000000: # 2 bytes return unpack(">H", bchr(b1 & 0b00111111) + self.read(1))[0] elif b1 & 0b00100000: # 3 bytes return unpack(">L", b"\0" + bchr(b1 & 0b00011111) + self.read(2))[0] elif b1 & 0b00010000: # 4 bytes return unpack(">L", bchr(b1 & 0b00001111) + self.read(3))[0] elif b1 & 0x00001000: # 5 bytes return unpack(">Q", b"\0\0\0" + bchr(b1 & 0b00000111) + self.read(4))[0] elif b1 & 0b00000100: # 6 bytes return unpack(">Q", b"\0\0" + bchr(b1 & 0b0000011) + self.read(5))[0] elif b1 & 0b00000010: # 7 bytes return unpack(">Q", b"\0" + bchr(b1 & 0b00000001) + self.read(6))[0] elif b1 & 0b00000001: # 8 bytes return unpack(">Q", b"\0" + self.read(7))[0] else: assert b1 == 0 raise EbmlException("undefined element size")I've a basic knowledge of bitwise operators via Google. I will get into more depth later. I just don't understand what this code is doing. What is
0b1000000I know it's a binary number, but what does the "0b" represent? I've seen "0x" prefacing binary numbers (though I don't really get what it means either), but never "0b".
I would appreciate any help decoding this for me.
Thanks,
malonn