Is the output correct for the following programs? I am using a Cygwin64 GCC compiler on a X86_64 Windows system. The architecture is little endian.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
float floatVal = 0x12345678;
do
{
printf("Hello World %f\n", floatVal);
floatVal++;
i++;
} while ( i < 10 );
return 0;
}
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Hello World 305419904.000000
Question 1: However this website gives me a completely different answer: http://www.binaryconvert.com/result_float.html?hexadecimal=12345678
Question 2: Why is the value not incrementing? The increments happen however if I use double instead of float.
What am I doing wrong?
Edit, after getting the correct answers:
After getting the correct answers from unwind, I have a further question and to do the same in Java. Since Java, does not use unions, is there a way to do the conversion from integer to float the same way as the accepted answer in C. I found the answer here :