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;
}
40 AC 00 00
04 CA 00 00
00 00 AC 40
00 00 CA 04
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
117 comments Page 7 of 12.

Himanshu said:   1 decade ago
Hi.

Rithvika normalization is one way to reduce the redundancy in table.

Surbhi said:   1 decade ago
What do you mean by big endian and little endian ?

Rithvika said:   1 decade ago
Hey can any one tell the procedure of normalisation?

Sairam said:   1 decade ago
Thanks preethi, visual, gaurav.

Raj said:   1 decade ago
In little endian, lower order bytes will be stored in lower addresses. But how this is the answer?

Gaurav Kumar said:   1 decade ago
Floating 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 bcoz 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

Rajasekaran said:   1 decade ago
Thank preeti and pradeep.

How do normaliize ? please say anyone for me.

Muthulakshmi said:   1 decade ago
How will I understand the c program easily I feel the programs are very difficult. It is easy or not and please teach me.

Santosh said:   1 decade ago
#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;
}

Please give me the description for how the above program is executing.

Nikita said:   1 decade ago
a=5.375 IS REPRESENTED AS '40 AC 00 00'. When stored in memory in case of little endian its stored as..

(eg.) 500 501 502 503
a = 00 00 AC 40

Now p=(char *)&a; means p will hold address of a and p is of char type so after typecasting it will hold 500 which hold 00, on incrementing it will print respective values.


Post your comments here:

Your comments will be displayed after verification.