24 bit signed integer binary conversion help needed

Grant Edwards invalid at invalid.invalid
Fri Jan 8 22:33:03 CET 2010

On 2010-01-08, Grant Edwards <invalid at invalid.invalid> wrote:
> On 2010-01-08, Robert Somerville <rsomerville at sjgeophysics.com> wrote:
>> I am trying to read 24bit signed WAV format (little endian) data from a 
>> WAV file and convert it to 32 bit little endian integer format ... can 
>> anybody please tell me how to do the conversion from 24 bit to 32 bit 
>> with a snippet of Python code ???
> def sext24(d):
>     if ord(d[2]) & 0x80:
>         return d+'\xff'
>     else:
>         return d+'\x00'

I guess I assumed you knew how to read 3 bytes of data from a

f = open('datafile','rb')
d = f.read(3)

Grant Edwards                   grante             Yow! I need to discuss
                                  at               BUY-BACK PROVISIONS
                               visi.com            with at least six studio

More information about the Python-list mailing list