# How to prove float is of 32 bit?

• 08-02-2009
anirban
How to prove float is of 32 bit?
How to prove using C program that float is of 32 bit?
• 08-02-2009
bithub
Code:

`printf("float size is %u bits\n", sizeof(float) * CHAR_BIT);`
• 08-02-2009
Salem
float.h
And associated constants.
• 08-02-2009
anirban
Thanks but i need to write the program using basic shift, logical and other operators...Is it possible?
• 08-02-2009
grumpy

Beyond that, I will say no more: your problem has all the hallmarks of a homework exercise, so you should look here.
• 08-02-2009
tabstop
Quote:

Originally Posted by anirban
Thanks but i need to write the program using basic shift, logical and other operators...Is it possible?

Nota bene: you cannot use shift or bitwise operators on a float variable.
• 08-02-2009
anirban
Yes that's true just discovered. So any other way plz?
• 08-02-2009
Sebastiani
Quote:

Originally Posted by anirban
Thanks but i need to write the program using basic shift, logical and other operators...Is it possible?

Utter nonsense.
• 08-02-2009
Brafil
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-2009
grumpy
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-2009
Brafil
And, for full portability, also check CHAR_BIT.