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 6 of 12.

Prabhjot said:   1 decade ago
Thank you preethi.

Nisha said:   1 decade ago
Thanks preethi.

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.

Sarava said:   1 decade ago
Thank you preethi.

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 ???

Binit said:   1 decade ago
Binary equivalent of 5 = 101 & 0.375 = 011
so 5.375= 101.011

Normalization means in the left side of decimal should only have one integer example: normalisation of 101.345 = 1.01345* 100

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
but intel follows little endianess so ans will be

C). 0000AC40

Hardik said:   1 decade ago
Thank you very much preety.

Shashikant said:   1 decade ago
Thank you to solve this problem.

Babu said:   1 decade ago
Hay can anyone please tell me what is memory normalization?

Yamuna said:   1 decade ago
I have one doubt here we used unsigned char why don't we use signed char ?


Post your comments here:

Your comments will be displayed after verification.