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 10 of 12.
Sudhir said:
1 decade ago
Here what is mean by printf("%02x\n", (unsigned char)p[i]); statement, please explain me.
Sayan bose said:
1 decade ago
How is hexadecimal operation taking place in a compiler?
Suresh Gupta said:
1 decade ago
We are use database in C or not ?
Sameer Sarkaar said:
1 decade ago
What is little endian?
Dheeraj said:
1 decade ago
Why we are using %02x? any one can explain me.
Venkatesh said:
1 decade ago
#include<stdio.h>
int main()
{
int i=1; // i=0001 it will store in memory like this 00000000 00000000 00000000 00000001
char *p; // p is declared as a char pointer
p=(char*)&i; //here integer is typecasting to char i.e. 00000001
00000000
00000000
00000000 and pointer is always points to starting address.
if(*p)
printf("=====little-endian);
else
printf("=====big-endian);
return 0;
}
int main()
{
int i=1; // i=0001 it will store in memory like this 00000000 00000000 00000000 00000001
char *p; // p is declared as a char pointer
p=(char*)&i; //here integer is typecasting to char i.e. 00000001
00000000
00000000
00000000 and pointer is always points to starting address.
if(*p)
printf("=====little-endian);
else
printf("=====big-endian);
return 0;
}
Anand said:
1 decade ago
Hexadecimal conversion of the variable in the code. That's it nothing more than that.
Tayyaba said:
1 decade ago
@Dheeraj. %02X means 1st two bytes.
Ravi jivani said:
1 decade ago
Its because the memory allocation type which intel CPU supports is little endian, so the last byte of the data stores first in the memory allocation unit. And the starting point of the pointer goes to that address. Its simple, just reverse the byte order of the binary equivalent data of the input value.
Sachin said:
1 decade ago
Intel processor store in reverse order.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers