Strainu onLine
Blogul unui automatist
8th
MAY
How to read the bits in a IEEE 754 number?
Posted by Strainu | Filed under C
That’s one of those questions you always wanted to know the answer to, but never found somebody who knew, right?
Well, in C it’s pretty simple. All you have to do is to declare an union, like this:
float f;
int bits;
}
This tells the compiler that both f and bits should be hold in the same memory zone. This is pretty useful to save some memory, if you know for sure that you wown’t need f and bits in the same time.
As a side effect, if you write a value in f then read bits, you will have all the bits represented in the IEEE 754 standard. Now you can use bit operations (& , | , ^) with your number, you can extract the different parts of the number, etc. Do keep in mind that this is bad programming practice.
Recent Posts:
- 28 Oct Some people just won̵...
- 18 Aug Wiki Loves Monuments RomÃ...
- 15 May Want to work on Pidgin or...
- 14 Apr Free WiFi in the metro!
- 04 Apr Libertatea dincolo de sof...
- 11 Feb Electrocasnice online: Do...
- 15 Oct Wikipedia română –...
- 14 Oct Veliko Tarnovo Sound ...
- 11 Oct Romanian Postal Codes in ...
- 11 Jul Wikimania 2010 – zi...






