Skip to content

Instantly share code, notes, and snippets.

@theredpea
Last active August 29, 2015 13:56
Show Gist options
  • Save theredpea/9333133 to your computer and use it in GitHub Desktop.
Save theredpea/9333133 to your computer and use it in GitHub Desktop.
from util import groupBy
_4b5bmap = {'11110':'0000',
'01001':'0001',
'11100':'1110',
'11101':'1111'}
#"are pre-determined in a dictionary and they are chosen to ensure that there will be at least two transitions per block of bits."
#TODO: Get the whole map from http://www.mathworks.com/matlabcentral/fileexchange/27566-4b5b-encoder-line-codificador-de-linea-4b5b/ ?
def translate4b5b(bits):
return [_4b5bmap.get(_5) for _5 in groupBy(bits,5)]
print(''.join(translate4b5b('1110011110')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment