Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: ricardo2013 en 11 Octubre 2012, 20:01 pm



Título: Imprimir float en hexadecimal
Publicado por: ricardo2013 en 11 Octubre 2012, 20:01 pm
¿Por qué no me funciona esto para imprimir un float en dígitos hexadecimales?

Código
  1.  
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.    float f = 5.5;
  7.    printf("%X\n", f);
  8.    return 0;
  9. }
  10.  
  11.  

Debería de salir (códificación IEEE 754): 80 B0 00 00
y da: DAC98408

Gracias anticipadas


Título: Re: Imprimir float en hexadecimal
Publicado por: avesudra en 11 Octubre 2012, 21:57 pm
Porque no estás usando el especificador de formato correcto:
Specifier                    Output                                            Example
a            Hexadecimal floating point, lowercase                -0xc.90fep-2
A            Hexadecimal floating point, uppercase               -0XC.90FEP-2
x            Unsigned hexadecimal integer                           7fa
X            Unsigned hexadecimal integer (uppercase)         7FA

Fuente : http://www.cplusplus.com/reference/clibrary/cstdio/printf/