you can use concept of union to display floating in binary

union x
{
  float z;
  int a;
};
set the value of z..and represent it by "a"

assuming int and float have same size


On Mon, Jan 23, 2012 at 8:42 AM, Ashish Goel <[email protected]> wrote:

>
>
> string ftob(string s)
> {
> int intPart= Integer.parseInt(s.substring(0, s.indexOf('.')));
> double fraction = Double.parseDouble(s.substring( s.indexOf('.'),
> s.length()));
> string intString="";
> while (intPart)
> {
>   int  bit=intPart&1;
>   intPart >>=1;
>   intString = bit + intString;
> }
>
> string fracString = ""; int fracLen = 0;
> while((fracLen <32) && (fraction>0))
> {
>   fraction *=2;
>   if (fraction>1) { fraction -=1; fracString.append('1');}
>   else { fracString.append('0');
>   fracLen++;
> }
> return (intString + '.' + fracString);
> }
>
>
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
>
> On Tue, May 24, 2011 at 12:09 PM, saurabh agrawal <[email protected]>wrote:
>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*Dheeraj Sharma*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to