Bits and bytes?

Scherer, Bill Bill.Scherer at VerizonWireless.com
Wed Jun 12 17:27:09 CEST 2002


On Wed, 12 Jun 2002, Guyon Morée wrote:

> ok, thanx a lot.
> 
> there's one thing i am missing though... how do i write '011010110101' as
> 'binary bits' to a file?

I've only had need for this once, but when I 'realized' that a 
byte was just eight bits, my problem was solved. For you that 
depends on if you're ok with writing bits in multiples of eight, 
and that you can create the proper 8 bit seqeunces for your 
needs.  chr(0) through chr(255) should cover your needs, I think.

chr(107) + chr(168) will give you

'011010110101000'

CAVEAT: I might be completely off my rocker on this. 8-)

Good luck.

> 
> 
> 
> 
> "Christopher Armstrong" <radix at twistedmatrix.com> wrote in message
> news:mailman.1023890477.2592.python-list at python.org...
> >>>>> "Guyon" == Guyon Moree <gumuz at looze.net> writes:
> 
>     Guyon> ok, this might be a strange question.... but i was wondering: how
>     Guyon> can i read or write 'bits'?
> 
>     Guyon> if i have a string, how can i convert to it's basic 0's and 1's?
> 
>     Guyon> and offcourse, the other way around.... let's say i want to store
>     Guyon> some bit-sequence(0011101110) to a file.
> 
> 
>     Guyon> how do i do this?
> 
> http://twistedmatrix.com/users/moshez/binary.py
> 
> Moshe Zadka wrote this because he was annoyed at all the people in #python
> asking how to do this ;-)
> 
> 
> --
>                                 Chris Armstrong
>                          << radix at twistedmatrix.com >>
>                 http://twistedmatrix.com/users/carmstro.twistd/
> 
> 
> 
> 
> 
> 

-- 
Bill.Scherer at Verizon Wireless
RHCE 807101044903581






More information about the Python-list mailing list