converting binary data
piotr maliński
riklaunim at gmail.com
Mon Feb 27 14:17:21 EST 2006
I have a game file described here:
http://iesdp.gibberlings3.net/ieformats/itm_v1.htm and I'm trying to read
all the data:
############################
plik = open('bow08.itm', 'rb')
try:
tekst = plik.read()
finally:
plik.close()
# char array - works
print tekst[0x0004:0x0004+4]
# resref - works
print tekst[0x003a:0x003a+8]
#dword - binary something, doesn't work
print tekst[0x004c:0x004c+4]
##############################
The dword and many other variables are binary code and I don't know how to
convert them into "normal" data. NearInfinity, app written in Java converts
dword and friends in this way:
##############################
public static int convertInt(byte buffer[], int offset)
{
int value = 0;
for (int i = 3; i >= 0; i--)
value = (value << 8) | (buffer[offset + i] & 0xFF);
return value;
}
##############################
How to pythonize this code, or make something in python to read the data
from Baldurs Gate files ? :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060227/645d3563/attachment.html>
More information about the Python-list
mailing list