X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=string_utils.py;h=a6a2da3155fcf312e9a9bc21ecd94f26141b4fcb;hb=9484900f080e16f118806fe54973e69d36b043e8;hp=623ae45f03e6eb12c608f966b421ba9c5495b0e9;hpb=a5c4feeac240a446a38147130b51ad96a046f6e1;p=python_utils.git diff --git a/string_utils.py b/string_utils.py index 623ae45..a6a2da3 100644 --- a/string_utils.py +++ b/string_utils.py @@ -1461,10 +1461,14 @@ def to_bitstring(txt: str, *, delimiter='', encoding='utf-8', errors='surrogatep >>> to_bitstring('test', delimiter=' ') '01110100 01100101 01110011 01110100' + >>> to_bitstring(b'test') + '01110100011001010111001101110100' + """ + etxt = to_ascii(txt) bits = bin( int.from_bytes( - txt.encode(encoding, errors), + etxt, 'big' ) )