This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Verifying my identity on Peepeth.com 0x1e7bcfbd53fdfb37541726a96fe97fac35e29ac6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_tbcd(binary_string): | |
""" | |
tbcd decoding in one line | |
function takes argument in a form "0b10110101001" and translates it into a string | |
presentation of integer by tbcd standards | |
http://en.wikipedia.org/wiki/Binary-coded_decimal#Telephony_Binary_Coded_Decimal_.28TBCD.29 | |
""" | |
return "".join(str(int(binary_string[index: index + 4], 2)) if int(binary_string[index + 4:index + 8], 2) == 15 else "%s%s" % (int(binary_string[index + 4:index + 8], 2), int(binary_string[index: index + 4], 2)) for index in range(2, len(binary_string), 8)) |