Write bits in file

Tim Roberts timr at probo.com
Thu May 22 00:52:16 EDT 2008


"sjdevnull at yahoo.com" <sjdevnull at yahoo.com> wrote:
>On May 20, 12:14 am, Tim Roberts <t... at probo.com> wrote:
>> Monica Leko <monica.l... at gmail.com> wrote:
>>
>> >I have a specific format and I need binary representation.  Does
>> >Python have some built-in function which will, for instance, represent
>> >number 15 in exactly 10 bits?
>>
>> For the record, I'd like to point out that even C cannot do this.  You need
>> to use shifting and masking to produce a stream of 8-bit bytes, or to
>> extract your values from a stream of 8-bit bytes.
>
>Technically specifying 8-bits isn't quite accurate, as C allows for 9-
>bit bytes and other variations depending on the architecture.  But
>that may be overly pedantic unless you have a PDP-10 laying around
>that you're writing C code on or something like that.

As long as we are being pedantic, and I don't mind that, I would point out
that I didn't actually say that C worked in 8-bit bytes.  I was very
careful to say merely that, assuming you wanted a stream of 8-bit bytes,
you need to use shifting and masking to produce it.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list