summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2017-12-09 17:25:53 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2017-12-09 17:25:53 +0100
commitc413347e757ede98757d0f5d629a73fb0736ed26 (patch)
tree974f29c20a413b723f16cfa47ff99d99c0e284c7 /decoders
parentb9b63977498f2114cf41d9039223481cbcaf3a45 (diff)
downloadlibsigrokdecode-c413347e757ede98757d0f5d629a73fb0736ed26.tar.gz
libsigrokdecode-c413347e757ede98757d0f5d629a73fb0736ed26.zip
graycode: Move bitpack/bitunpack to common/.
Diffstat (limited to 'decoders')
-rw-r--r--decoders/common/srdhelper/mod.py14
-rw-r--r--decoders/graycode/pd.py15
2 files changed, 15 insertions, 14 deletions
diff --git a/decoders/common/srdhelper/mod.py b/decoders/common/srdhelper/mod.py
index 4871205..b559c95 100644
--- a/decoders/common/srdhelper/mod.py
+++ b/decoders/common/srdhelper/mod.py
@@ -20,3 +20,17 @@
# Return the specified BCD number (max. 8 bits) as integer.
def bcd2int(b):
return (b & 0x0f) + ((b >> 4) * 10)
+
+def bitpack(bits):
+ res = 0
+ for i, b in enumerate(bits):
+ res |= b << i
+ return res
+
+def bitunpack(num, minbits=0):
+ res = []
+ while num or minbits > 0:
+ res.append(num & 1)
+ num >>= 1
+ minbits -= 1
+ return tuple(res)
diff --git a/decoders/graycode/pd.py b/decoders/graycode/pd.py
index 2edc837..f500c83 100644
--- a/decoders/graycode/pd.py
+++ b/decoders/graycode/pd.py
@@ -20,20 +20,7 @@
import math
import sigrokdecode as srd
from collections import deque
-
-def bitpack(bits):
- res = 0
- for i, b in enumerate(bits):
- res |= b << i
- return res
-
-def bitunpack(num, minbits=0):
- res = []
- while num or minbits > 0:
- res.append(num & 1)
- num >>= 1
- minbits -= 1
- return tuple(res)
+from common.srdhelper import bitpack, bitunpack
def gray_encode(plain):
return plain & (plain >> 1)