[python-win32] ATT DSP32C to IEEE

Ray Schumacher rays at blue-cove.com
Fri Jan 13 20:03:11 CET 2006


Thanks Thomas

Is there not much call for DSP32 use, with Python?
A modified Python float() function, that accepts IEEE or DSP32 would be ideal.
Something like: float(string, type=DSP32)

For now, my last posted implementation is sufficient.
arrf = array.array('f')
DSP32ToIEEE(arrf, struct.unpack('L', fh.read(4))[0])

def DSP32ToIEEE(arrf, longVal):
    if not longVal>>31:
        arrL[0] = ((longVal & 0x000000ff)<<23)+((longVal & 0x7fffffff)>>8)
        arrf.fromstring(arrL.tostring())
        arrf[0] = arrf[0]/2.
    else:
        arrL[0] = (1<<31)+((longVal & 0x000000ff)<<23)+ ~((longVal & 0x7fffffff)>>8)
        arrf.fromstring(arrL.tostring())
    return arrf.pop() 

Ray

At 09:20 AM 1/13/2006, Thomas Heller wrote:

>>>You could try ctypes bitfield structures, maybe, to access the fields?
>>
>> Sounds interesting, but I have not used them; and on
>> http://starship.python.net/crew/theller/ctypes/tutorial.html
>> you wrote
>> "Bugs, ToDo and non-implemented things
>> Bitfields are not implemented."
>> Are they available? Documented?
>> I have __version__ = "0.9.6"
>
>Available - yes (also in 0.9.6 I think).  Documented - no.
>
>
>> I also just read
>> http://publications.gbdirect.co.uk/c_book/chapter6/bitfields.html
>> which warned "Be careful using them. It can require a surprising
>> amount of run-time code to manipulate these things and you can end up
>> using more space than they save.  Bit fields do not have addresses­you
>> can't have pointers to them or arrays of them."
>
>This is probably true, but meant as a warning to C programmers.
>Apparently when using predefined structures you have no other choice
>than to use them.
>
>Thomas
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32 at python.org
>http://mail.python.org/mailman/listinfo/python-win32



More information about the Python-win32 mailing list