Conversion of 24bit binary to int

Idar ip at itk.ntnu.no
Tue Nov 11 06:41:27 EST 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:
for(i=0;i<nchn;i++)
	{	
	for(k=0;k<segl;k++)
		{
		ar24[k]=0;//output array=32 bit int array->Mt24 fmt
		pdt=(unsigned char *)(&ar24[k]);
		*pdt    =*(a+2);
		*(pdt+1)=*(a+1);
		*(pdt+2)=*(a+0);
		a+=3;
		ar24[k]-=DownloadDataOffset;
//		printf("%d\n",ar24[k]);//this is the number on 32 bit format
		}
	}





More information about the Python-list mailing list