MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / text_from_bits

Function text_from_bits

hashes/hamming_code.py:61–67  ·  view source on GitHub ↗

>>> text_from_bits('011011010111001101100111') 'msg'

(bits, encoding="utf-8", errors="surrogatepass")

Source from the content-addressed store, hash-verified

59
60
61def text_from_bits(bits, encoding="utf-8", errors="surrogatepass"):
62 """
63 >>> text_from_bits('011011010111001101100111')
64 'msg'
65 """
66 n = int(bits, 2)
67 return n.to_bytes((n.bit_length() + 7) // 8, "big").decode(encoding, errors) or "\0"
68
69
70# Functions of hamming code-------------------------------------------

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected