<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Homework help please!! Desperate!! For loops and binary representation' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Homework help please!! Desperate!! For loops and binary representation' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2008 Programmers Heaven</copyright>
    <pubDate>Tue, 13 May 2008 20:57:38 -0700</pubDate>
    <lastBuildDate>Tue, 13 May 2008 20:57:38 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Homework help please!! Desperate!! For loops and binary representation</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/370660/370660/ReadMessage.aspx</link>
      <description>&lt;div class="BoardMessageAreaPrinterFriendly"&gt;
&lt;h2 class="BoardMessageSubjectPrinterFriendly"&gt;Homework help please!! Desperate!! For loops and binary representation&lt;/h2&gt;
&lt;div class="BoardMessageInfoPrinterFriendly"&gt;Posted by  on 27 Mar 2008 at 4:37 PM&lt;/div&gt;
&lt;div class="BoardMessageBodyPrinterFriendly"&gt;Hi&lt;br /&gt;
&lt;br /&gt;
I am trying to write a program that displays all the bits of the binary representation of the type float.&lt;br /&gt;
&lt;br /&gt;
The program needs to display info like this Example. (User enters the number 6). &lt;br /&gt;
&lt;br /&gt;
This program displays a binary representation of real numbers.&lt;br /&gt;
Enter a real number: 6&lt;br /&gt;
&lt;br /&gt;
The number's representation is 32 bits long:&lt;br /&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;br /&gt;
01000000110000000000000000000000&lt;br /&gt;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;br /&gt;
&lt;br /&gt;
sign: 0&lt;br /&gt;
exponent: 10000001&lt;br /&gt;
mantissa: 10000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
To display the bits I have to use the for loop. &lt;br /&gt;
&lt;br /&gt;
There is a skeleton program which has to be used and only edited within int main:&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
/*************************************************
***************&lt;br /&gt;
* skeleton program file float.cpp &lt;br /&gt;
* This program calculate calculates and displays a binary&lt;br /&gt;
*   representation of real numbers.&lt;br /&gt;
* Assume all input is of the correct format.&lt;br /&gt;
*&lt;br /&gt;
* Input:  a real number.&lt;br /&gt;
*&lt;br /&gt;
* Output: The bit pattern of the number stored in the computer's&lt;br /&gt;
*    memory as float&lt;br /&gt;
*&lt;br /&gt;
* Processing: &lt;br /&gt;
*         .......&lt;br /&gt;
*&lt;br /&gt;
* Author: &lt;br /&gt;
*&lt;br /&gt;
**************************************************
******************/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;         // for cin and cout&lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;          // for setw()&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
// prototype&lt;br /&gt;
int TestBit( unsigned bit, float number );&lt;br /&gt;
&lt;br /&gt;
// start of the program&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
&lt;br /&gt;
} // of main()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
* TestBit: tests bits of a float number&lt;br /&gt;
* receive: a bit where 0 is the rightmost bit&lt;br /&gt;
*         and a number to test&lt;br /&gt;
* return: 1 if the bit is set on, 0 therwise&lt;br /&gt;
* preconditions: bit is in the range 0..31&lt;br /&gt;
*/&lt;br /&gt;
int TestBit( unsigned bit, float number )&lt;br /&gt;
{&lt;br /&gt;
	if ( bit &amp;lt; 8*sizeof(number) )&lt;br /&gt;
		if ( ((( unsigned int) 1) &amp;lt;&amp;lt; bit) &amp;amp; (*((unsigned int*)(&amp;amp;number))) )&lt;br /&gt;
			return 1;&lt;br /&gt;
	return 0;&lt;br /&gt;
	&lt;br /&gt;
} // TestBit&lt;br /&gt;
&lt;br /&gt;
I am completely lost. I do not understand how to write a for loop into it or return the particular bit of the float number. I have spent days trying to work it out. If anyone could help by giving me an example of how it works or showing me how to do it I would really appreciate it.&lt;br /&gt;
I have done all of the formatting and the prompt for real number etc (i think), I am just stuck on the 0's and 1's parts. It has just completely gone over my head.&lt;br /&gt;
&lt;br /&gt;
I tried searching for info on the net 'c++ help', 'for loop', 'for loop c++', 'binary representation c++', 'binary representation for loop', and alot more (in google and yahoo searches). I cannot find anything simple enough for me to understand.&lt;br /&gt;
&lt;br /&gt;
As far as i know i can only add to the int main on the skeletal program. Not really sure. The main problem is that I do not understand how to write a for loop into it or return the particular bit of the float number. I have spent days trying to work it out. I have done all of the formatting and the prompt for real number etc, I am just stuck on the 0's and 1's parts. It has just completely gone over my head.&lt;br /&gt;
&lt;br /&gt;
Please help. I am really desperate now and running out of time.&lt;br /&gt;
&lt;br /&gt;
Thank you......&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 27 Mar 2008 16:37:37 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>