This snippet defines a function a2bits
which converts a characters string to a string of 0's and 1's showing its bitwise representation.
String to Bits
import sys
if sys.version_info[0] >= 3:
bin = "{0:#0b}".format
from functools import reduce
def a2bits(chars):
"Convert a string to its bits representation as a string of 0's and 1's"
return bin(reduce(lambda x, y : (x<<8)+y, (ord(c) for c in chars), 1))[3:]
Gribouillis 1,391 Programming Explorer Team Colleague
Gribouillis 1,391 Programming Explorer Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.