@immanuel:
in this part
while (decimalPart > 0 && decimalPart < 1 && str.length < 64) {
decimalPart *= 2;
str[str.length] = (decimalPart - 0) + '0';
}
is this decimalPart-0 correct here?
if decimalpart (say) starts as 0.584 then after doing that into 2 we 1.164.
What happens next according to your code?
On Tue, May 24, 2011 at 1:45 AM, immanuel kingston <
[email protected]> wrote:
> correct me if I am wrong.
>
> String convertFloatToBinary(float num) {
> String str = "";
> int numBeforeDecimal = (int)num;
> float decimalPart = num - (float)numBeforeDecimal;
> int sign=1;
> if (numBeforeDecimal < 0 ) sign = -1;
> if (sign < 0) str[str.length] = '-';
> while(numBeforeDecimal > 0) {
> str[str.length] = numBeforeDecimal % 2 + '0';
> numBeforeDecimal /= 2;
> }
> str[str.length] = '.';
> while (decimalPart > 0 && decimalPart < 1 && str.length < 64) {
> decimalPart *= 2;
> str[str.length] = (decimalPart - 0) + '0';
> }
> return str;
> }
>
> Thanks,
> Immanuel
>
>
> On Tue, May 24, 2011 at 12:15 PM, Naveen Kumar <[email protected]
> > wrote:
>
>> http://kipirvine.com/asm/workbook/floating_tut.htm
>>
>>
>>
>> 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.
>>>
>>
>>
>>
>> --
>> Cheers
>> Naveen Kumar
>>
>> --
>> 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.
>
--
"People often say that motivation doesn't last. Well, neither does bathing
- that's why we recommend it daily."
--
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.