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 11 of 12.
Deepak naik said:
1 decade ago
What is normalised form in C?
Swathi said:
1 decade ago
Can you explain the program for me once again and also the execution part also.
Prabhudeva 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.
And 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.
And 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.
Manisha Sehgal said:
1 decade ago
Intel chips are usually Little Endian when it comes to store data in data space. But for storing machine code in code segment the same chip is Big Endian.
Pramod Kumar said:
1 decade ago
p = (char*)&a;
Can anyone explain meaning of this line?
Can anyone explain meaning of this line?
Shubham Gorde said:
10 years ago
For little Indian method, least significant bytes stored first (means at lowest address).
Address value.
503 0100 0000.
502 1010 1100.
501 0000 0000.
500 0000 0000.
And statement p = (char *) &a:: stores low byte address (i.e 500 here) of 1 into p (as p is char pointer).
So answer is 00 00 AC 40.
Address value.
503 0100 0000.
502 1010 1100.
501 0000 0000.
500 0000 0000.
And statement p = (char *) &a:: stores low byte address (i.e 500 here) of 1 into p (as p is char pointer).
So answer is 00 00 AC 40.
Usman ali ar said:
10 years ago
Why it is C than B?
Shyam said:
10 years ago
Hi answer is C please any one can explain?
Rahul said:
10 years ago
0100 -> 4
0000 -> 0
1010 -> A
1100 -> C
0000 -> 0
0000 -> 0
0000 -> 0
0000 -> 0
How to convert this why we are using 4, A, C, 0, 0?
0000 -> 0
1010 -> A
1100 -> C
0000 -> 0
0000 -> 0
0000 -> 0
0000 -> 0
How to convert this why we are using 4, A, C, 0, 0?
Sargam said:
9 years ago
The data type of 'a' is in 'float' but the pointer variable used for that is in 'char'. So is it possible to take float type value in character data type?
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers