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 2 of 12.
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.
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.
Anuj said:
1 decade ago
Preethi's answer is absolutly correct.
Ankit Chandra said:
1 decade ago
Thank you preeti. I really needed that ansswer badly.
Subrata said:
1 decade ago
Thank you preeti.
Aishwarya said:
1 decade ago
I agree with preeti answer.
Vishnu kant said:
1 decade ago
Thanks preethi. Thanks pradeep. :-).
Nikhil kadam said:
1 decade ago
Why we tha answer is not 00 00 CA 04?
Nikhil said:
1 decade ago
Thanks preethi.
Reka said:
1 decade ago
How to normalise a number?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers