make dec8.bit.Bitfield reversible

This commit is contained in:
Martin Sekera 2020-09-08 02:42:15 +02:00
parent e8dfe4790e
commit 10d356225d

View file

@ -12,7 +12,21 @@ class Bitfield:
self.value <<= length
self.value |= value
self.length += length
def shift_out(self, length):
mask = 2**length - 1
tmp = self.value & mask
self.value >>= length
return tmp
def load(self, raw):
self.value = 0
self.length = 0
for b in raw:
self.shift_in(b, 8)
def dump(self, align=True):
value = self.value
length = self.length