Wednesday, April 11, 2012

Typecasting or accessing char array to integer array in Python

I have a char array in Python, which is read from a file e.g.



char_array = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]


how do i convert/typecast/access this to an array of integers like



int_array[0] = 0x03020100
int_array[1] = 0x07060504
int_array[2] = 0x0b0a0908
int_array[3] = 0x0f0e0d0c


similar to how one would access an array of bytes as integers in C/C++ i.e. type cast an unsigned char * to an unsigned long *.





No comments:

Post a Comment