I have instructions concerning the structure of a binary file and I'm trying to build a parser to get information from the binary file. I was doing quite alright till i came across the following:
Start with a DWORD Size = 0. You're going to reconstruct the size by getting packs of 7 bits:
Get a byte.
Add the first 7 bits of this byte to Size.
Check bit 7 (the last bit) of this byte. If it's on, go back to 1. to process the next byte.
To resume, if Size < 128 then it will occupy only 1 byte, else if Size < 16384 it will occupy only 2 bytes and so on...
What I'm confused about is what it means to "get bits from a byte", and to "check the last bit of the byte". This is the way I've been reading bytes from the file:
from struct import *
#..... some other blocks of code
self.standard = {"DWORD":4,"WORD": 2,"BYTE": 1,"TEXT11": 1,"TEXT12": 2}
st = st = self.standard
size = 0
data = unpack("b", f.read(st["BYTE"]))
#how to get bits???
if size < 128:
#use st["TEXT11"]
elif size < 16384:
#use st["TEXT12"]