M
manuel
How to convert a decimal to binary ?
thx,
Manuel
thx,
Manuel
manuel said:How to convert a decimal to binary ?
manuel said:How to convert a decimal to binary ?
How to convert a decimal to binary ?
thx,
Manuel
manuel said: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))
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.
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]?
[1, 1, 1, 0, 0, 1, 0, 0]digitlist(234) # binary 11101010 [0, 1, 0, 1, 0, 1, 1, 1]
digitlist(39) # binary 00100111
manuel said:if listByte[17] & (1 << 3):
Thanks!
But I don't understand completely the meaning of
& (1 << 3)
Can you suggest me a page in python on line manual,
or a tutorial?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.