Conversion of 24bit binary to int

Idar ip at
Tue Nov 11 12:41:27 CET 2003

Is there an effecient/fast way in python to convert binary data from file 
(24bit hex(int) big endian) to 32bit int (little endian)? Have seen 
struct.unpack, but I am unsure how and what Python has to offer. Idar

The orginal data format is stored in blocks of 512 words 
(1536B=3Bytes/word) on the form Ch1: 1536B (3B*512), the binary (hex) data 
is big endian
Ch2: 1536B (3B*512)
Ch3: 1536B (3B*512)
and so on

The equivalent c++ program looks like this:
		ar24[k]=0;//output array=32 bit int array->Mt24 fmt
		pdt=(unsigned char *)(&ar24[k]);
		*pdt    =*(a+2);
//		printf("%d\n",ar24[k]);//this is the number on 32 bit format

More information about the Python-list mailing list