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 3 of 12.
Suvidha said:
1 decade ago
In the statement p= (char*) &a; we are doing type casting since p is a char pointer you cannot assign float variable to it a pointer variable can hold the address of another variable only if the variable has the same data type of that as pointer variable.
Kali said:
1 decade ago
@ Binit :
" So normalized form is 1.01011*100
So according to IEEE notation 5.375 can be represented as
0100 0000 1010 1100 this can be expressed as 40AC0000 "
how did you convert the 1.01011 no into normalized form 0100 0000 1010 1100 ???
" So normalized form is 1.01011*100
So according to IEEE notation 5.375 can be represented as
0100 0000 1010 1100 this can be expressed as 40AC0000 "
how did you convert the 1.01011 no into normalized form 0100 0000 1010 1100 ???
Yash said:
1 decade ago
Someone is asked why we taking 2 byte not 1 byte like 00 00 AC 40 not like 00 CA 04 because processors work on hexadecimal no on octal. So we take 2 byte or 16 bit instead of 1 byte or 8 bit.
@ Preethi
Thank you very much.
@ Preethi
Thank you very much.
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.
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
MOHD ILYAS DCET said:
1 decade ago
The above explanations are correct I would like to give an idea about another method of arrangement i.e 'Big-endian' here we can arrange 1234 as 3-4-1-2 or 2-1-4-3 in the memory addresses
Yerasi Krishna Narasimha Reddy said:
1 year ago
There is an option error.
Actually, the correct one is Option A.
8086 microprocessors store data in hexadecimal.
0100-4.
0000-0.
1010-A.
1100-c.
0000-0.
0000-0.
0000-0.
0000-0.
Actually, the correct one is Option A.
8086 microprocessors store data in hexadecimal.
0100-4.
0000-0.
1010-A.
1100-c.
0000-0.
0000-0.
0000-0.
0000-0.
(3)
Divya said:
1 decade ago
@ Hajmal
They gave the binary equivalent of 5.375 in normal form
0100 -> 4
0000 -> 0
1010 -> A
1100 -> C
0000 -> 0
0000 -> 0
0000 -> 0
0000 -> 0
They gave the binary equivalent of 5.375 in normal form
0100 -> 4
0000 -> 0
1010 -> A
1100 -> C
0000 -> 0
0000 -> 0
0000 -> 0
0000 -> 0
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....
Satti said:
1 decade ago
Satish, p declared as a character pointer,so a is not a character type. so we can covert a type to p char type.
char *p;
int i=10;
p=(char*)i;// type casting is done.
char *p;
int i=10;
p=(char*)i;// type casting is done.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers