Re: How to Convert a string into binary

2006-04-15 Thread Grant Edwards
On 2006-04-16, John Machin <[EMAIL PROTECTED]> wrote: > On 16/04/2006 5:25 AM, HNT20 wrote: >> >> hi --> 011011101001 >> > > This implies that the bits in a byte are transmitted MSB first. I > haven't done anything anywhere near this area since about the time that > acoustic couplers went

Re: How to Convert a string into binary

2006-04-15 Thread Jesse Hager
The short version: def str2bin(s): return ''.join([''.join(['10'[not (m&ord(x))] for m in (128,64,32,16,8,4,2,1)]) for x in s]) Notes: Split into 3 lines for newsgroup post, 3rd line is actually the end of the 2nd. It will run as shown above. Returns digits in MSB order, to return L

Re: How to Convert a string into binary

2006-04-15 Thread John Machin
On 16/04/2006 5:25 AM, HNT20 wrote: > > hi --> 011011101001 > This implies that the bits in a byte are transmitted MSB first. I haven't done anything anywhere near this area since about the time that acoustic couplers went the way of buggy whips, but my vague recollection is LSB first

Re: How to Convert a string into binary

2006-04-15 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-15 às 18:09 -0400, Terry Reedy escreveu: > # given string s > binchars = [] > for c in s: binchars.append(a2b[ord(c)]) Faster: binchars = [a2b[ord(c)] for c in s] -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Convert a string into binary

2006-04-15 Thread Terry Reedy
"HNT20" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > i am new to python language. i am working on a gnuradio project where it > uses python as the primary programming language. i am trying to convert > a message, text, or numbers into binary code so that i can process it. >

Re: How to Convert a string into binary

2006-04-15 Thread HNT20
Felipe Almeida Lessa wrote: > Em Sáb, 2006-04-15 às 19:25 +, HNT20 escreveu: >> is there a way to convert a string into its binary representation of the >> ascii table.?? > > I'm very curious... why? > > And no, I don't have the answer. > well, once i get the binary representations, i can

Re: How to Convert a string into binary

2006-04-15 Thread HNT20
Rune Strand wrote: > HNT20 wrote: >> Hello All >> > > def ascii_to_bin(char): > ascii = ord(char) > bin = [] > > while (ascii > 0): > if (ascii & 1) == 1: > bin.append("1") > else: > bin.append("0") > ascii = ascii >> 1 > > bin.reve

Re: How to Convert a string into binary

2006-04-15 Thread HNT20
[EMAIL PROTECTED] wrote: > If (assuming this is correct, you can do more tests) the given strings > are many and/or long, this can be a fast version. With Psyco this same > version can become quite faster. > Bye, > bearophile > > > from array import array > > class ToBinary(object): > """ToB

Re: How to Convert a string into binary

2006-04-15 Thread Fredrik Lundh
"HNT20" <[EMAIL PROTECTED]> wrote: > i am new to python language. i am working on a gnuradio project where it > uses python as the primary programming language. i am trying to convert > a message, text, or numbers into binary code so that i can process it. umm. characters and numbers are stored

Re: How to Convert a string into binary

2006-04-15 Thread bearophileHUGS
If (assuming this is correct, you can do more tests) the given strings are many and/or long, this can be a fast version. With Psyco this same version can become quite faster. Bye, bearophile from array import array class ToBinary(object): """ToBinary: class to convert a given string to a bin

Re: How to Convert a string into binary

2006-04-15 Thread Duncan Booth
HNT20 wrote: > is there a way to convert a string into its binary representation of the > ascii table.?? > > an example of what i want would be: > > hi --> 011011101001 Why not just write some code to do it? e.g. >>> def b1(n): return "01"[n%2] >>> def b2(n): return b1(n>>1)+b1

Re: How to Convert a string into binary

2006-04-15 Thread Rune Strand
HNT20 wrote: > Hello All > def ascii_to_bin(char): ascii = ord(char) bin = [] while (ascii > 0): if (ascii & 1) == 1: bin.append("1") else: bin.append("0") ascii = ascii >> 1 bin.reverse() binary = "".join(bin) zerofix = (8

Re: How to Convert a string into binary

2006-04-15 Thread Felipe Almeida Lessa
Em Sáb, 2006-04-15 às 19:25 +, HNT20 escreveu: > is there a way to convert a string into its binary representation of the > ascii table.?? I'm very curious... why? And no, I don't have the answer. -- Felipe. -- http://mail.python.org/mailman/listinfo/python-list

How to Convert a string into binary

2006-04-15 Thread HNT20
Hello All i am new to python language. i am working on a gnuradio project where it uses python as the primary programming language. i am trying to convert a message, text, or numbers into binary code so that i can process it. i googled many times and tried many of the answers out there, no luck