Doble a Binario

Doble a Binario

Postby damosi » Mon Jan 15, 2007 12:20 pm

Saludos a todos/as,

Tiene FW alguna funcion para pasar un signed float (double 8 bytes) a binario, de forma similar a como lo hace W2BIN() con los signed integer de 2 bytes??

Harbour no la tiene.

Gracias!!
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Postby Antonio Linares » Tue Jan 16, 2007 3:26 am

Prueba con esta función:
Code: Select all  Expand view
HB_FUNC( F2BIN )
{
   char szString[ 4 ];

   if( ISNUM( 1 ) )
   {
      float fValue = ( float ) hb_parnd( 1 );

      szString[ 0 ] = ( fValue & 0x00FF );
      szString[ 1 ] = ( fValue & 0xFF00 ) >> 8;
      szString[ 2 ] = ( fValue & 0x00FF0000 ) >> 16;
      szString[ 3 ] = ( fValue & 0xFF000000 ) >> 24;
   }
   else
   {
      szString[ 0 ] = '\0';
   }

   hb_retclen( szString, 4 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41937
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby damosi » Tue Jan 16, 2007 10:39 am

Antonio he intentado compilar y me da 4 errores:

Error E2060 prueba.prg 10: Illegal use of floating point in function HB_FUN_F2BIN.
Error E2060 prueba.prg 11: Illegal use of floating point in function HB_FUN_F2BIN.
Error E2060 prueba.prg 12: Illegal use of floating point in function HB_FUN_F2BIN.
Error E2060 prueba.prg 13: Illegal use of floating point in function HB_FUN_F2BIN.

Correspondientes a cada asignación en el array szString

Estoy compilando con Borland C++ 5.51 y Harbour Alpha 45.0
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Postby Antonio Linares » Tue Jan 16, 2007 11:23 am

Cambia estas cuatro líneas:

szString[ 0 ] = * ( char * ) &fValue;
szString[ 1 ] = * ( ( char * ) &fValue + 1 );
szString[ 2 ] = * ( ( char * ) &fValue + 2 );
szString[ 3 ] = * ( ( char * ) &fValue + 3 );
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41937
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Tue Jan 16, 2007 12:02 pm

Mucho más simple:
Code: Select all  Expand view
HB_FUNC( F2BIN )
{
   float fValue = hb_parnd( 1 );

   hb_retclen( ( char * ) &fValue, 4 );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41937
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby damosi » Tue Jan 16, 2007 12:32 pm

Antonio,

Ahora si parece funcionar pero necesito que devuelva un float con signo de doble presición o sea 8 bytes no 4.

Hay alguna manera de incluir esta función en un .hrb? al compilar y ejecutar si me reconoce la función f2bin() pero si intento ejecutarlo con hbrun me falla me dice que no conoce o no esta registrado el símbolo f2bin.
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Postby damosi » Tue Jan 16, 2007 12:42 pm

Antonio he probado con

HB_FUNC( D2BIN )
{
double fValue = hb_parnd( 1 );

hb_retclen( ( char * ) &fValue, 8 );
}

Y funciona correctamente, sólo me queda saber cómo se podría utilizar con hbrun
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Postby Antonio Linares » Tue Jan 16, 2007 2:09 pm

Al construir hbrun tienes que incluir esta nueva función
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41937
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby damosi » Tue Jan 16, 2007 4:09 pm

Muchas gracias Antonio.
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 37 guests