Skip to content

fphammerle/python-manchester-code

Repository files navigation

manchester-code

Code style: black CI Pipeline Status Last Release Compatible Python Versions DOI

Python library to encode & decode data as Manchester code

Setup

$ pip3 install --user --upgrade manchester-code

Usage

0-bits translate to low-high, 1-bits to high-low (G. E. Thomas convention).

from manchester_code import encode, decode, decode_bits

manchester_code = encode([0b00001111, 0b01101001])
print(''.join(f'{m:08b}' for m in manchester_code))
# 01010101101010100110100110010110

encode(b'msg')
# b'i\xa6jZij'

decode([0b01010101, 0b10101010, 0b01101001, 0b10010110])
# 0000111101101001

decode(b'ieiVjeiV')
# b'data'

list(decode_bits([False, True, True, False]))
# [False, True]

list(decode_bits([0, 1, 1, 0, 0, 1, 0, 1]))
# [False, True, False, False]