Floating point to hexadecimal, arranged by the most "important" bits
Hi, I have this assignment to do, in which the program asks the user for floating point input, after getting this the floating point is printed as a hexadecimal bit by bit, arranging so that the most important bit is first etc.
This is what I get, it seems to work quite properly on presenting the hexadecimal sometimes. Sometimes it just prints a whole lot of F's even though they really should not be there. Could someone please guide me to the righ direction?
Clearly I'm not arranging these yet, first I'd like it to present the data correctly.
Code:
#include <stdio.h>
int main (void)
{
int i;
double nbr;
char *ptr;
printf("Type a floating point:\n");
scanf("%lf", &nbr);
ptr = &nbr;
printf("\Number %lf as a hexadecimal is \n", nbr);
for(i=0;i<sizeof(double);i++)
printf("%X ", *ptr++);
return 0;
}