On Tue, 07 Nov 2006 18:27, you wrote:
> On Tue, 07 Nov 2006 17:53:51 +1300
>
> Don Gould <[EMAIL PROTECTED]> wrote:
> > Is there a quick way of dumping some text out as binary?
> >
> > ie:  "Hello world" -->
> > 11010101010101111101110101011101010101010110101010101010101010110101111
> >110111010

In Python, using information found here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/219300

>>> def tobin(x, count=8):
...         """
...         Integer to binary
...         Count is number of bits
...         """
...         return "".join(map(lambda y:str((x>>y)&1), \
...             range(count-1, -1, -1)))
...
>>> foo = 'Hello world'
>>> for c in foo:
...     print "\b"+ tobin(ord(c)),
...
0100100001100101011011000110110001101111001000000111011101101111011100100110110001100100
>>>

Python, as always, is your friend.

A

Reply via email to