From: Martin on
On Jun 7, 9:57 am, "Alfred Bovin" <alf...(a)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 looked at the numpy libraries?

It would be very easy to do...

import numpy as np

f = open("something.bin", "rb")
data = np.fromfile(f, np.uint8)
data = np.where(data == 0, data * 5, data)

So in this example I am just saying if data = 0, multiply by 5. This
saves the need for slow loops as well.

Mart.