How to prove using C program that 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?...
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.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
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?
24bbs.cppCode:if( numeric_limits< byte >::digits != bits_per_byte ) error( "program requires bits_per_byte-bit bytes" );
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.
Right 98% of the time, and don't care about the other 3%.
And, for full portability, also check CHAR_BIT.