decimal to binary

manuel manuelbastioniNOSPAM at tin.it
Fri Jul 25 14:52:00 EDT 2003


> We probably need more information than that to answer your question.

I'm writing a script for Blender to make a true displacement
feature. This is a sample:
http://www.kino3d.com/forum/files/test4.jpg

and this is the discussion:
http://www.elysiun.com/forum/viewtopic.php?t=13135&postdays=0&postorder=asc&
start=0


Please, excuse me for my poor english, it's very
hard for me to explain a development question,
because I'm italian, and I've little time to study
other language...Really I prefer study 3D and python. :-P
The main problem with newsgroup it that
after send the message I can't modify it... :-(

This is the first time that I try to handle
binary file.

I read a tga file, and store all bytes in a list:

---------------------------------------
#LETTURA DEL FILE TGA
 listByte = []
 try:
  f = open(filename,'rb')
 except IOError,(errno,strerror):
  msgstring = "I/O error(%s): %s" % (errno, strerror); Draw()
  return
 fileReaded = f.read();
 msgstring = "Parsing tga..."; Draw()
 for i in range(len(fileReaded)):
  listByte.append(ord(fileReaded[i]))
 f.close()
------------------------------------------

I use ord() to convert the value of byte in
integer, if I don't make this, I've the ASCII
symbol...

But, for listByte[17], I must read the sequence
of 0 and 1, because I must know the 4° and 5° bit:
this bits specify the image origin.

How I can read the 4° and 5° bit from listByte[17]?

Thanks,

        Manuel Bastioni










More information about the Python-list mailing list