How to prove using C program that float is of 32 bit?
How to prove using C program that float is of 32 bit?
Code:printf("float size is %u bits\n", sizeof(float) * CHAR_BIT);
Last edited by bithub; 08-02-2009 at 01:02 AM.
bit∙hub [bit-huhb] n. A source and destination for information.
float.h
And associated constants.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Thanks but i need to write the program using basic shift, logical and other operators...Is it possible?
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.
Yes that's true just discovered. So any other way plz?
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)
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.
And, for full portability, also check CHAR_BIT.