0

I am working on a program that will convert a floating point number base ten to its binary representation base two. I understand that we cannot use bit wise operators on floating point numbers, but I am told that if we use a cast to convert it to an unsigned int, we can. using unsigned int float_int = ((unsigned int)&f). My assignment states that we can separate out the two fields using bit wise operators. I have tried everything, but I cannot come up with a solution that will separate a number from it's decimal.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Your cast is invalid, and will also break [*strict aliasing*](http://stackoverflow.com/questions/98650/what-is-the-strict-aliasing-rule). To be correct you should make a bitwise copy (with e.g. `std::memcpy`) into an array of `char` large enough for the type, then do another bitwise copy to a suitable integer type (e.g. `uint32_t` for a 32-bit `float` value). *Then* you can start working on the bits. – Some programmer dude Apr 20 '17 at 14:54
  • What is the representation of a floating point number base ten? I think if you want help with this assignment you will have to provide more information. I suspect that what you have is a text string that needs to be converted to a variable of type 'float', but you'll have to clarify. – Arunas Apr 21 '17 at 23:57

0 Answers0