How to prove using C program that float is of 32 bit?

Printable View

- 08-02-2009anirbanHow to prove float is of 32 bit?
How to prove using C program that float is of 32 bit?

- 08-02-2009bithubCode:
`printf("float size is %u bits\n", sizeof(float) * CHAR_BIT);`

- 08-02-2009Salem
float.h

And associated constants. - 08-02-2009anirban
Thanks but i need to write the program using basic shift, logical and other operators...Is it possible?

- 08-02-2009grumpy
To answer your question literally: yes, it is possible.

Beyond that, I will say no more: your problem has all the hallmarks of a homework exercise, so you should look here. - 08-02-2009tabstop
- 08-02-2009anirban
Yes that's true just discovered. So any other way plz?

- 08-02-2009Sebastiani
- 08-02-2009Brafil
Sebastiani is right. Binary operators are not portably supported for floats (binary in terms of shift/and, not like + or &&) and very complicated - I really doubt you need them. Logicals & other operators are well supported (except %, you'll need fmod)

- 08-02-2009grumpy
It is not necessary to use bitwise operations on float variables for this. The only information needed is the size of the type and the number of bits in a variable of that size. The relationship between sizeof(type) and number of bits in a type is fixed for any given implementation.

sizeof() is an operator with pretty well-defined semantics, after all, and bitwise operations are readily applicable to char types.

The only exception would be processor and memory architectures that do not involve bits. But such architectures are pretty rare practically, and the question is meaningless on them anyway. - 08-03-2009Brafil
And, for full portability, also check CHAR_BIT.