On Jun 7, 9:57 am, "Alfred Bovin" wrote:
> Hi all.
>
> I'm working on something where I need to read a (binary) file bit by bit and
> do something depending on whether the bit is 0 or 1.
>
> Any help on doing the actual file reading is appreciated.
>
> Thanks in advance
Hi,
Have you looked at th
On 6/7/2010 6:20 AM, Ulrich Eckhardt wrote:
Ulrich Eckhardt wrote:
data = f.read()
for byte in data:
for i in range(8):
bit = 2**i& byte
...
Correction: Of course you have to use ord() to get from the single-element
string ("byte" above) to its integral
On 2010-06-07, Richard Thomas wrote:
> You're reading those bits backwards. You want to read the most
> significant bit of each byte first...
Can you explain the reasoning behind that assertion?
--
Grant Edwards grant.b.edwardsYow! I can't decide which
superpollo wrote:
> mine goes like this:
>
> >>> bin(192)
> Traceback (most recent call last):
>File "", line 1, in
> NameError: name 'bin' is not defined
Yep, one of mine, too. The "bin" function was new in 2.6, as were binary
number literals ("0b1100").
Uli
--
Sator Laser GmbH
Geschäft
Ulrich Eckhardt ha scritto:
Peter Otten wrote:
Ulrich Eckhardt wrote:
Says Python:
bin(192)
'0x1100'
Hmm, if that's what /your/ Python says, here's mine to counter:
bin(192)
'0_totally_faked_binary_0011'
Argh! Of course one of my Pythons says '0b1100' and not what I mistype
Peter Otten wrote:
> Ulrich Eckhardt wrote:
>> Says Python:
>>
> bin(192)
>> '0x1100'
>
> Hmm, if that's what /your/ Python says, here's mine to counter:
>
bin(192)
> '0_totally_faked_binary_0011'
Argh! Of course one of my Pythons says '0b1100' and not what I mistyped
above
Ulrich Eckhardt wrote:
> Nobody wrote:
>> On Mon, 07 Jun 2010 02:31:08 -0700, Richard Thomas wrote:
>>
>>> You're reading those bits backwards. You want to read the most
>>> significant bit of each byte first...
>>
>> Says who?
>
> Says Python:
>
bin(192)
> '0x1100'
Hmm, if that's wh
Nobody wrote:
> On Mon, 07 Jun 2010 02:31:08 -0700, Richard Thomas wrote:
>
>> You're reading those bits backwards. You want to read the most
>> significant bit of each byte first...
>
> Says who?
Says Python:
>>> bin(192)
'0x1100'
That said, I totally agree that there is no inherently rig
On Mon, 07 Jun 2010 02:31:08 -0700, Richard Thomas wrote:
> You're reading those bits backwards. You want to read the most
> significant bit of each byte first...
Says who?
There is no universal standard for bit-order.
Among bitmap image formats, XBM is LSB-first while BMP and PBM are
MSB-first
Richard Thomas wrote:
> On Jun 7, 10:17 am, Peter Otten <__pete...@web.de> wrote:
>> Alfred Bovin wrote:
>> > I'm working on something where I need to read a (binary) file bit by
>> > bit and do something depending on whether the bit is 0 or 1.
>>
>> > Any help on doing the actual file reading is
On 06/07/10 19:31, Richard Thomas wrote:
> On Jun 7, 10:17 am, Peter Otten <__pete...@web.de> wrote:
>> Alfred Bovin wrote:
>>> I'm working on something where I need to read a (binary) file bit by bit
>>> and do something depending on whether the bit is 0 or 1.
>>
>>> Any help on doing the actual f
Ulrich Eckhardt wrote:
>data = f.read()
>for byte in data:
>for i in range(8):
>bit = 2**i & byte
>...
Correction: Of course you have to use ord() to get from the single-element
string ("byte" above) to its integral value first.
Uli
--
Sator Laser GmbH
Ge
On Jun 7, 10:17 am, Peter Otten <__pete...@web.de> wrote:
> Alfred Bovin wrote:
> > I'm working on something where I need to read a (binary) file bit by bit
> > and do something depending on whether the bit is 0 or 1.
>
> > Any help on doing the actual file reading is appreciated.
>
> The logical u
Alfred Bovin wrote:
> I'm working on something where I need to read a (binary) file bit by bit
> and do something depending on whether the bit is 0 or 1.
>
> Any help on doing the actual file reading is appreciated.
The logical unit in which files are written is the byte. You can split the
byte
Alfred Bovin wrote:
> I'm working on something where I need to read a (binary) file bit by bit
> and do something depending on whether the bit is 0 or 1.
Well, smallest unit you can read is an octet/byte. You then check the
individual digits of the byte using binary masks.
f = open(...)
da
Hi all.
I'm working on something where I need to read a (binary) file bit by bit and
do something depending on whether the bit is 0 or 1.
Any help on doing the actual file reading is appreciated.
Thanks in advance
--
http://mail.python.org/mailman/listinfo/python-list
16 matches
Mail list logo