# How to prove float is of 32 bit?

This is a discussion on How to prove float is of 32 bit? within the C Programming forums, part of the General Programming Boards category; How to prove using C program that float is of 32 bit?...

1. ## How to prove float is of 32 bit?

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

2. Code:
`printf("float size is %u bits\n", sizeof(float) * CHAR_BIT);`

3. float.h
And associated constants.

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

Beyond that, I will say no more: your problem has all the hallmarks of a homework exercise, so you should look here.

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

7. Yes that's true just discovered. So any other way plz?

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

9. 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)

10. 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.

11. And, for full portability, also check CHAR_BIT.