C Programming - Floating Point Issues - Discussion
Discussion Forum : Floating Point Issues - General Questions (Q.No. 3)
3.
If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?
#include<stdio.h>
#include<math.h>
int main()
{
float a=5.375;
char *p;
int i;
p = (char*)&a;
for(i=0; i<=3; i++)
printf("%02x\n", (unsigned char)p[i]);
return 0;
}
Discussion:
117 comments Page 12 of 12.
Anuj said:
1 decade ago
Preethi's answer is absolutly correct.
Vikesh said:
1 decade ago
There is different number system is binary and hexadecimal. Our Turbo C is machine dependent. So we get this type of result. In real Digital logic we get different result. Because we get resut in binary.
Pradeep said:
1 decade ago
Yeah she is correct but in the end only.
Take one more example:
Say we have to store 0102 0304H in memory (where H : for hexadecimal code).
Say initial memory address is 100H. Then
and in BIG Endian MSB(most significant bit) is stored at lowest address location (as in my example 01 is the MSB) while Little Endian format follows the exactly opposite trend.
So now as the PC's (intel processors) use " LITTLE ENDIAN" byte order, The result is written from bottom to top.
Take one more example:
Say we have to store 0102 0304H in memory (where H : for hexadecimal code).
Say initial memory address is 100H. Then
Memory Address | Big endian | Little Endian
100 : | 01 | 04
101 : | 02 | 03
102 : | 03 | 02
103 : | 04 | 01
and in BIG Endian MSB(most significant bit) is stored at lowest address location (as in my example 01 is the MSB) while Little Endian format follows the exactly opposite trend.
So now as the PC's (intel processors) use " LITTLE ENDIAN" byte order, The result is written from bottom to top.
Mini said:
1 decade ago
I think preethi is correct.
Preethi said:
2 decades ago
Binary equivalent of 5.375 in normalised form is
0100 -> 4
0000 -> 0
1010 -> A
1100 -> C
0000 -> 0
0000 -> 0
0000 -> 0
0000 -> 0
Since the PC's (intel processors) use " LITTLE ENDIAN" byte order, the higher order byte of number is stored in lowest address. The result is written from bottom to top.
0100 -> 4
0000 -> 0
1010 -> A
1100 -> C
0000 -> 0
0000 -> 0
0000 -> 0
0000 -> 0
Since the PC's (intel processors) use " LITTLE ENDIAN" byte order, the higher order byte of number is stored in lowest address. The result is written from bottom to top.
(1)
Padhu said:
2 decades ago
Its because the machine in which that program executed remains a little endian machine. See this for explanation:
http://www.indiabix.com/c-programming/floating-point-issues/discussion-146
http://www.indiabix.com/c-programming/floating-point-issues/discussion-146
Siva said:
2 decades ago
Can you please give the explanation in detail?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers