Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/06/2011, 08:54
javiquero
 
Fecha de Ingreso: octubre-2010
Mensajes: 12
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: Microsoft Binary Format

Si, perdona.

Básicamente me pasa un Array de 4 bytes a tipo Long.

Toda la documentación que he encontrado por internet hace referencia a funciones MBR to IEEE bajo windows, aunque tambien he visto la equivalente en pyhton, pero como no tengo ni idea...

la pongo en pyhton por si a alguien le pueda servir:

Código PHP:
def fmsbin2ieee(self,bytes):
    
"""Convert an array of 4 bytes containing Microsoft Binary floating point
    number to IEEE floating point format (which is used by Python)"""
    
as_int = struct.unpack("i", bytes)
    if 
not as_int:
        return 
0.0
    man 
= long(struct.unpack('H', bytes[2:])[0])
    
exp = (man & 0xff00) - 0x0200
    
if (exp & 0x8000 != man & 0x8000):
        return 
1.0
        
#raise ValueError('exponent overflow')
    
man = man & 0x7f | (man << 8) & 0x8000
    man 
|= exp >> 1
    bytes2 
= bytes[:2]
    
bytes2 += chr(man & 255)
    
bytes2 += chr((man >> 8) & 255)
    return 
struct.unpack("f", bytes2)[0] 

Última edición por javiquero; 09/06/2011 a las 09:09