On Jun 7, 9:57 am, Alfred Bovin alf...@bovin.invalid 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
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
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(...)
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
bytes
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 unit in
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
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 file reading is
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 appreciated.
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.
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 right way and
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 what /your/ Python says,
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 =(
Uli
*goes
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
superpollo wrote:
mine goes like this:
bin(192)
Traceback (most recent call last):
File stdin, line 1, in module
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
On 2010-06-07, Richard Thomas chards...@gmail.com 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
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
16 matches
Mail list logo