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 9 of 12.
Vinay said:
1 decade ago
Vishal pandey is correct but how you can normalised the last address p[3]=00000000 10000000 as 40.
Raji said:
1 decade ago
Thanks preethi.
Well wisher said:
1 decade ago
Preethi's explanation is reall good.
Some asked why not D ?.
If you see the things.
0102
02 is in separate address.
O1 is in very next address.
In case of little endian.
To know what exactly happens refer to some microprocessor book it will give you a clear idea.
Some asked why not D ?.
If you see the things.
0102
02 is in separate address.
O1 is in very next address.
In case of little endian.
To know what exactly happens refer to some microprocessor book it will give you a clear idea.
John said:
1 decade ago
Can someone tell me how to normalise ?
Tushar & Mitesh said:
1 decade ago
In Question it is not mention on which processor program is compiled and
in option Big endian answer is also there hence we can't say what will be the correct answer....
in option Big endian answer is also there hence we can't say what will be the correct answer....
Vishal pandey said:
1 decade ago
Foating point base conversion of 5.375 would be
101.01100 00000000 00000000 00000000 00000000 00000000 00000000 10000000
(char*) will be make it as a character array.
5.375 = 101.01100 00000000 00000000 00000000 00000000 00000000 00000000 10000000
nd coz of unsigned char, it wud be treated as,
p[0] = 00000000 00000000
p[1] = 00000000 00000000
p[2] = 10101100 00000000
p[2] = 00000000 10000000
=> in hexadecimal form (%02x) :
p[0] = 00
p[1] = 00
p[2] = ac
p[3] = 40
101.01100 00000000 00000000 00000000 00000000 00000000 00000000 10000000
(char*) will be make it as a character array.
5.375 = 101.01100 00000000 00000000 00000000 00000000 00000000 00000000 10000000
nd coz of unsigned char, it wud be treated as,
p[0] = 00000000 00000000
p[1] = 00000000 00000000
p[2] = 10101100 00000000
p[2] = 00000000 10000000
=> in hexadecimal form (%02x) :
p[0] = 00
p[1] = 00
p[2] = ac
p[3] = 40
Shwetha said:
1 decade ago
If we go according to preethi the answer should be 00 00 CA 04
but the answer given is 00 00 AC 40
but the answer given is 00 00 AC 40
Anusha said:
1 decade ago
@amith: the ans is C bcoz it is considered byte wise
Amit said:
1 decade ago
Why it is c? why not d?
Muthu said:
1 decade ago
Preethi answer is good.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers