Help/example of bit testing
François Granger
francois.granger at free.fr
Thu Dec 7 15:45:05 EST 2000
Bryan Webb <bww00 at amdahl.com> wrote:
> Hi,
> I am reading a file (binary)of 1024 char recs (bitmaps) . I can read the
> file , bit im having trouble finding examples of testing bits. I need to
> look at each bit of the above record.
> Looking for examples and ideas.
I got inspired by an algorithm by Tim Peters, so I did a quick hack in
order to display in binary form. It need some polishing.
l = [1, 2, 3, 4, 8, 16, 32, 64, 128, 255, 512, 1024, 2048, 4096, 8192,
16384, 32768]
def toBin(x):
a = ''
y = x
while x:
x, y = x / 2, y % 2
if y:
a = '1' + a
else:
a = '0' + a
y = x
return
for x in l:
print toBin(x)
--
Une faq de frj: http://faq.jardin.free.fr/, près de l'encyclopédie
http://nature.jardin.free.fr/
More information about the Python-list
mailing list