I am trying to write a program that displays all the bits of the binary representation of the type float.

The program needs to display info like this Example. (User enters the number 6).

This program displays a binary representation of real numbers.

Enter a real number: 6

The number's representation is 32 bits long:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

01000000110000000000000000000000

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sign: 0

exponent: 10000001

mantissa: 10000000000000000000000

Notes:

To display the bits I have to use the for loop.

There is a skeleton program which is this:

/**************************************************************** * skeleton program file float.cpp * This program calculate calculates and displays a binary * representation of real numbers. * Assume all input is of the correct format. * * Input: a real number. * * Output: The bit pattern of the number stored in the computer's * memory as float * * Processing: * ....... * * Author: * ********************************************************************/ #include <iostream> // for cin and cout #include <iomanip> // for setw() using namespace std; // prototype int TestBit( unsigned bit, float number ); // start of the program int main() { return 0; } // of main() /* * TestBit: tests bits of a float number * receive: a bit where 0 is the rightmost bit * and a number to test * return: 1 if the bit is set on, 0 therwise * preconditions: bit is in the range 0..31 */ int TestBit( unsigned bit, float number ) { if ( bit < 8*sizeof(number) ) if ( ((( unsigned int) 1) << bit) & (*((unsigned int*)(&number))) ) return 1; return 0; } // TestBit

I am completely lost. I can do all of the setup part and make it look like the example but I dont know how to get all of the zero's and ones and/or break it up into the segments. I am stuck on the for loop too. I also cannot work out what the skeleton prog is supposed to do and how we are supposed to use it?

I do not expect anyone to do this for me I just need to know how to do it. If you are able to show me how to make this work i would really appreciate it.

Can anyone help me??? Please??