#NEWLINE# def dec_to_bcd_8421( num ) : #NEWLINE# #INDENT# 'Convert a decimal to binary, and decompress into Binary Coded Decimal.\n    Adds trailing bits to the left to enforce a 4-bit "nibble" on all digits.\n    Uses 8421 notation [see wikipedia.org/wiki/Binary-coded_decimal]' #NEWLINE# ( bcd , binary , decimals ) = ( '' , '' , '' ) #NEWLINE# for digit in str ( num ) : #NEWLINE# #INDENT# binval = encoders . dec_to_bin ( int ( num ) ) #NEWLINE# binary += '{}{}' . format ( binval , ( ' ' * ( ( 4 - len ( binval ) ) + 1 ) ) ) #NEWLINE# if ( len ( binval ) < 4 ) : #NEWLINE# #INDENT# binval = binval . zfill ( 4 ) #NEWLINE# #UNINDENT# bcd += '{} ' . format ( binval ) #NEWLINE# decimals += ( digit + ( ' ' * 4 ) ) #NEWLINE# #UNINDENT# _show_bcd ( num , decimals , binary , bcd ) #NEWLINE# return bcd