Re: how the following code works?
On Jun 16, 10:38 am, Ravi <ra.ravi....@xxxxxxxxx> wrote:
main() {
float a = 5.375;
char *p;
int i;
p = (char*)&a;
for(i=0;i<=3;i++)
printf("%02x",(unsigned char)p);
}
oops, you had taken liberty over the size of float!
printf("%02x",(unsigned char)p);
Never know what you are trying to do by this statement.
the above code gives the binary representation of a.
No, it doesn't!
Moreover, even if you correct all the mistakes, I don't think you will
get the binary representation, unless CHAR_BIT==1,in which case your
implementation is non-conforming!
You will get only "byte representation".
how does it work?
It doesn't work at all.
.
Relevant Pages
- Re: What is a "floating-point integer representation"?
... Basically, every float has a binary representation, and every binary representation can be expressed as a base-10 integer. ... The reason for representing a float as an integer is that you can write it to a text file without loosing any significance. ... make sure that the machines respect the same storage when reading/writing the data between different machines.) ... % trimmed float ... (comp.soft-sys.matlab) - Re: Binary Decimals in Python
... Is this by design? ... The int() constructor returns integers. ... look to float() for non-integral values. ... Binary representation isn't supported yet, ... (comp.lang.python) - Re: What is a "floating-point integer representation"?
... Basically, every float has a binary representation, and every binary representation can be expressed as a base-10 integer. ... The reason for representing a float as an integer is that you can write it to a text file without loosing any significance. ... However, in the help of the hex2dec function itself is IMO no reference to the float part necessary, since we only operate with a string and an integer. ... (comp.soft-sys.matlab) - Re: integer to float
... I currently start to work with an TI dsp ... My question is whats happen when I cast an 32Bit integer value ... > into an 32bit float value. ... The binary representation of the integer changes. ... (comp.dsp) - Re: Simple program - Where have i gone wrong?
... Oops: read a 'float' into 'a' ... Remember the format specifier are different for printf() and scanf ... (alt.comp.lang.learn.c-cpp) |
|