Convert to Integer in Python
Name:
Anonymous
2008-06-10 14:03
def readBMP( filename):
f = file( filename)
content = f.read()
f.close()
return content
def getDimensions( bytes):
return bytes[18:22],bytes[22:26]
w,h = getDimensions( getBMP( 'test.bmp'))
how do i convert w and h to int?
atm (w,h) == ('\x05\x00\x00\x00', '\x05\x00\x00\x00')
Name:
Cudder
!MhMRSATORI!FBeUS42x4uM+kgp
2012-05-26 7:11
This is the sort of thing that happens when you try to use a scripting language oriented towards text processing for binary data.
struct {
int a;
int b;
} d;
...
fread(&d, 1, sizeof(d), pfile);
...
... d.a ...
... d.b ...
Or if you don't care for defining structures/the offsets aren't fixed just use *(your_desired_type)(ptr + byte_offs) to pick out the pieces directly.
Newer Posts