From: Gerhard Sittig Date: Wed, 12 Aug 2020 16:46:28 +0000 (+0200) Subject: sdq: use common bits to number conversion X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2bb149e691be4e1abf664a346b0d97c3eac0ad3b;p=libsigrokdecode.git sdq: use common bits to number conversion --- diff --git a/decoders/sdq/pd.py b/decoders/sdq/pd.py index 80b15ff..1dc9c1c 100644 --- a/decoders/sdq/pd.py +++ b/decoders/sdq/pd.py @@ -17,6 +17,7 @@ ## along with this program; if not, see . ## +from common.srdhelper import bitpack import sigrokdecode as srd class SamplerateError(Exception): @@ -58,12 +59,6 @@ class Decoder(srd.Decoder): def putbetu(self, data): self.put(self.bytepos, self.startsample + int(self.bit_width), self.out_ann, data) - def bits2num(self, bitlist): - number = 0 - for i in range(len(bitlist)): - number += bitlist[i] * 2**i - return number - def __init__(self): self.reset() @@ -89,7 +84,7 @@ class Decoder(srd.Decoder): self.putetu([0, ['Bit: %d' % bit, '%d' % bit]]) if len(self.bits) == 8: - byte = self.bits2num(self.bits) + byte = bitpack(self.bits) self.putbetu([1, ['Byte: %#04x' % byte, '%#04x' % byte]]) self.bits = [] self.bytepos = 0